:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel2: #fafbfc;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e3e6ea;
  --line-soft: #f0f2f4;
  --accent: #3d6df2;
  --accent-soft: #e8eefe;
  --danger: #d23b3b;
  --shadow: 0 6px 24px rgba(15, 23, 42, .14);
  --gutter: 52px;
  --hh: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --panel: #1d2025;
    --panel2: #22262c;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2e333a;
    --line-soft: #262a30;
    --accent: #6b8fff;
    --accent-soft: #26304a;
    --danger: #ff6b6b;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* display 指定のある要素でも hidden 属性で確実に隠す */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer;
}
button:hover { background: var(--panel2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.icon { padding: 4px 10px; font-size: 18px; line-height: 1; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- ヘッダー ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.tabs { display: flex; gap: 2px; }
.tabs button { border: none; background: none; padding: 6px 12px; border-radius: 6px; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.cal-ctrl { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap; }
.cal-ctrl h1 { font-size: 17px; margin: 0 8px; min-width: 190px; font-weight: 600; }
.cal-ctrl #newEventBtn { margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 5px 11px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { flex: 1; min-height: 0; position: relative; }
#calView, #todoView { height: 100%; }
#todoView { overflow: auto; }

/* ---------- 共通 todo アイテム ---------- */
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo {
  display: flex; align-items: center; gap: 4px; min-height: 22px;
  padding: 1px 2px; border-radius: 4px; line-height: 1.3;
}
.todo:hover { background: rgba(127, 127, 127, .1); }
.todo input[type=checkbox] { margin: 0 2px; flex: none; cursor: pointer; width: 14px; height: 14px; accent-color: var(--accent); }
.t-title { flex: 1; min-width: 0; overflow-wrap: anywhere; cursor: text; }
.todo.done .t-title { text-decoration: line-through; color: var(--muted); }
.t-edit { flex: 1; min-width: 0; padding: 1px 4px; border-radius: 4px; }
.t-due { font-size: 11px; color: var(--muted); flex: none; }
.t-due.over { color: var(--danger); font-weight: 600; }
.t-btn {
  flex: none; border: none; background: none; padding: 0 4px; color: var(--muted);
  visibility: hidden; font-size: 13px; line-height: 18px;
}
.t-btn:hover { color: var(--text); background: none; }
.t-del:hover { color: var(--danger); }
.todo:hover .t-btn, .todo:focus-within .t-btn { visibility: visible; }
.add-todo { margin: 0; }
.add-todo input {
  width: 100%; border: 1px dashed transparent; background: transparent; padding: 2px 4px; font-size: 12px;
}
.add-todo input::placeholder { color: var(--muted); }
.add-todo input:hover { border-color: var(--line); }
.add-todo input:focus { background: var(--panel); border-style: solid; }
.add-todo.boxed input { border-color: var(--line); font-size: 14px; padding: 6px 8px; }

/* ---------- 月表示 ---------- */
.month { display: flex; flex-direction: column; height: 100%; background: var(--panel); }
.m-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.m-head div { text-align: center; padding: 6px 0; font-size: 12px; color: var(--muted); }
.m-grid { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: repeat(6, minmax(0, 1fr)); }
.m-cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 2px 4px; display: flex; flex-direction: column; min-height: 0; }
.m-cell:nth-child(7n) { border-right: none; }
.m-cell.other { background: var(--panel2); }
.m-cell.other .m-num { color: var(--muted); }
.m-num {
  align-self: flex-start; border: none; background: none; padding: 1px 6px; border-radius: 12px; font-size: 12px;
}
.m-cell.today .m-num { background: var(--accent); color: #fff; }
.sun { color: #d34f4f; } .sat { color: #3b78d8; }
.m-items { flex: 1; overflow: auto; min-height: 0; font-size: 12px; }
.m-ev {
  display: flex; gap: 4px; align-items: center; padding: 1px 4px; margin: 1px 0; border-radius: 4px; cursor: pointer;
  white-space: nowrap; overflow: hidden;
}
.m-ev:hover { filter: brightness(.96); }
.m-ev.timed::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.m-ev.allday { background: var(--c); color: #fff; }
.m-ev .tm { color: var(--muted); flex: none; }
.m-ev .ttl { overflow: hidden; text-overflow: ellipsis; }
.prog { margin-left: auto; font-size: 10px; padding: 0 5px; border-radius: 8px; background: rgba(127, 127, 127, .18); flex: none; }
.prog.complete { background: #22a06b; color: #fff; }
.m-items .todo { font-size: 12px; min-height: 18px; }

/* ---------- 週・日表示（タイムグリッド） ---------- */
.tg { height: 100%; overflow: auto; background: var(--panel); }
.tg-inner { min-width: calc(var(--gutter) + var(--n) * 130px); }
.tg-row { display: grid; grid-template-columns: var(--gutter) repeat(var(--n), minmax(0, 1fr)); }
.tg-top { position: sticky; top: 0; z-index: 30; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.tg-dh { text-align: center; padding: 4px 0; border-left: 1px solid var(--line); }
.tg-dh button { border: none; background: none; display: inline-flex; align-items: baseline; gap: 6px; padding: 2px 8px; border-radius: 8px; }
.tg-dh .wd { font-size: 12px; color: var(--muted); }
.tg-dh .dn { font-size: 18px; font-weight: 600; }
.tg-dh.today .dn { color: #fff; background: var(--accent); border-radius: 14px; padding: 0 7px; }
.tg-ad-label { font-size: 11px; color: var(--muted); text-align: right; padding: 4px 6px 0 0; }
.tg-ad { border-left: 1px solid var(--line); border-top: 1px solid var(--line-soft); padding: 2px 3px; max-height: 28vh; overflow: auto; font-size: 12px; }
.ad-ev { display: flex; gap: 4px; align-items: center; background: var(--c); color: #fff; border-radius: 4px; padding: 1px 6px; margin-bottom: 2px; cursor: pointer; }
.ad-ev .ttl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-ev .prog { background: rgba(255,255,255,.3); }
.tg-ad .add-todo input { opacity: 0; }
.tg-ad:hover .add-todo input, .tg-ad .add-todo input:focus { opacity: 1; }

.tg-body { position: relative; }
.tg-times { position: relative; height: calc(var(--hh) * 24); }
.tg-hl { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-50%); }
.tg-col {
  position: relative; height: calc(var(--hh) * 24); border-left: 1px solid var(--line);
  background-image: linear-gradient(to bottom, var(--line-soft) 1px, transparent 1px);
  background-size: 100% var(--hh);
  cursor: crosshair; user-select: none;
}
.tg-col.today { background-color: color-mix(in srgb, var(--accent) 3%, transparent); }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: #e5484d; z-index: 15; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: #e5484d; }
.ghost { position: absolute; left: 2px; right: 4px; background: color-mix(in srgb, var(--accent) 25%, transparent); border: 1px solid var(--accent); border-radius: 6px; font-size: 11px; padding: 2px 6px; pointer-events: none; z-index: 25; }

/* 予定ボックス：todo を内包するバー */
.ev {
  position: absolute; height: var(--h); overflow: hidden; z-index: 10;
  background: color-mix(in srgb, var(--c) 16%, var(--panel));
  border-left: 3px solid var(--c); border-radius: 6px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 30%, transparent);
  display: flex; flex-direction: column; cursor: default; user-select: text;
  transition: box-shadow .12s;
}
.ev:hover, .ev:focus-within {
  height: auto; min-height: var(--h); z-index: 20; overflow: visible;
  box-shadow: var(--shadow), 0 0 0 1px color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 12%, var(--panel));
}
.ev.dragging { height: var(--h) !important; overflow: hidden; opacity: .85; pointer-events: none; z-index: 40; }
.ev-head {
  display: flex; align-items: baseline; gap: 6px; padding: 2px 6px 1px; cursor: grab; flex: none;
  font-size: 12px; user-select: none;
}
.ev-head:active { cursor: grabbing; }
.ev-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.ev-time { font-size: 11px; color: var(--muted); flex: none; }
.ev-todos { padding: 0 3px; font-size: 12px; }
.ev-todos .todo { min-height: 20px; }
.ev .add-todo { padding: 0 3px 3px; }
.ev-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; cursor: ns-resize; }
.ev:hover .ev-resize { background: linear-gradient(transparent 2px, color-mix(in srgb, var(--c) 50%, transparent) 2px, transparent 4px); }

/* ---------- Todo タブ ---------- */
.todo-page { max-width: 860px; margin: 0 auto; padding: 20px 16px 60px; }
.todo-new { display: flex; gap: 8px; }
.todo-new input[name=title] { flex: 1; font-size: 15px; padding: 8px 10px; }
.todo-toolbar { display: flex; align-items: center; gap: 12px; margin: 14px 0 6px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; }
.group { margin-top: 18px; }
.group h3 { font-size: 12px; color: var(--muted); margin: 0 0 4px; font-weight: 600; display: flex; gap: 6px; }
.group h3.over { color: var(--danger); }
.group .todo-list { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.group .todo { padding: 7px 10px; border-radius: 0; border-top: 1px solid var(--line-soft); gap: 8px; }
.group .todo:first-child { border-top: none; }
.group .todo input[type=checkbox] { width: 16px; height: 16px; }
.t-ev {
  flex: none; max-width: 220px; font-size: 11px; padding: 1px 8px; border-radius: 10px; border: none;
  background: color-mix(in srgb, var(--c) 16%, var(--panel)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.t-date { flex: none; width: 132px; padding: 2px 4px; font-size: 12px; border-color: transparent; background: transparent; }
.t-date:hover { border-color: var(--line); }
.t-date.set { color: var(--accent); font-weight: 600; }
.t-date.over { color: var(--danger); }
.t-memo { flex: none; color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---------- ダイアログ ---------- */
.dlg { border: none; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(10, 14, 22, .35); }
.dlg-body { padding: 18px 20px 6px; max-height: calc(100vh - 140px); overflow: auto; }
.dlg h2 { margin: 0 0 12px; font-size: 16px; }
.dlg-foot { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.fld > span { font-size: 12px; color: var(--muted); }
.fld input, .fld select, .fld textarea { width: 100%; }
.chk { display: inline-flex; gap: 6px; align-items: center; margin-bottom: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dt { display: flex; gap: 4px; }
.dt input[type=date] { flex: 1.4; min-width: 0; }
.dt input[type=time] { flex: 1; min-width: 0; }
.all-day .dt input[type=time] { display: none; }
.colors { display: flex; gap: 6px; }
.colors label { width: 24px; height: 24px; border-radius: 50%; background: var(--c); cursor: pointer; position: relative; }
.colors input { position: absolute; opacity: 0; }
.colors label:has(input:checked) { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--c); }
#evTodos { margin-bottom: 4px; }
#evTodos .todo { padding: 4px 4px; }

/* ---------- トースト ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #1f2328; color: #fff; padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center;
}
#toast button { background: none; border: none; color: #8fb0ff; font-weight: 600; padding: 0; }

@media (max-width: 720px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .cal-ctrl h1 { min-width: 0; font-size: 15px; }
  .row2 { grid-template-columns: 1fr; }
  .t-date { width: 118px; }
  .t-ev { max-width: 110px; }
}

/* =========================================================
 * テンプレート・繰り返し
 * ======================================================= */
#calView { display: flex; flex-direction: column; }
#calBody { flex: 1; min-height: 0; }
#tplView { height: 100%; overflow: auto; }

.tpl-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 16px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line); font-size: 12px;
}
.tpl-bar .lbl { color: var(--muted); margin-right: 2px; }
.tpl-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 14px; font-size: 12px;
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
  background: color-mix(in srgb, var(--c) 12%, var(--panel)); cursor: grab; user-select: none; touch-action: none;
}
.tpl-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tpl-chip small { color: var(--muted); }
.tpl-chip:active { cursor: grabbing; }
.tpl-bar .ghost-btn { border-style: dashed; border-radius: 14px; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.tpl-drag {
  position: fixed; z-index: 200; pointer-events: none; padding: 4px 10px; border-radius: 6px; font-size: 12px;
  background: var(--c); color: #fff; box-shadow: var(--shadow); transform: translate(8px, 8px); white-space: nowrap;
}
.drop-hl { outline: 2px solid var(--accent); outline-offset: -2px; background-color: var(--accent-soft) !important; }

/* todo の種類マーク */
.t-kind {
  flex: none; display: inline-block; font-size: 10px; line-height: 15px; padding: 0 4px; border-radius: 4px;
  font-weight: 600; vertical-align: middle;
}
.k-repeat { background: color-mix(in srgb, #3d6df2 16%, transparent); color: #3d6df2; }
.k-once   { background: color-mix(in srgb, #c27c0e 18%, transparent); color: #b06d00; }
@media (prefers-color-scheme: dark) {
  .k-repeat { color: #8fb0ff; } .k-once { color: #f0b54a; }
}
.ev-tpl { font-size: 10px; color: var(--muted); flex: none; }

/* 予定ボックス内の追加フォーム（種類切替つき） */
.add-todo { display: flex; gap: 3px; align-items: center; }
.kind-btn {
  flex: none; font-size: 10px; padding: 0 5px; line-height: 16px; border-radius: 4px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); display: none;
}
.ev:hover .kind-btn, .ev:focus-within .kind-btn { display: inline-block; }
.kind-btn[data-kind=repeat] { color: #3d6df2; border-color: currentColor; }
.kind-btn[data-kind=once] { color: #b06d00; border-color: currentColor; }
.kind-sel { flex: none; width: auto; padding: 5px 6px; }

/* ダイアログ */
.tpl-info { font-size: 12px; color: var(--muted); margin-bottom: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tpl-info:empty { display: none; }
.link { border: none; background: none; color: var(--accent); padding: 0; text-decoration: underline; cursor: pointer; }
.link:hover { background: none; }
.repeat-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 2px; margin-bottom: 12px; background: var(--panel2); }
.repeat-box .fld { margin-bottom: 8px; }
.wd-pick { display: flex; gap: 4px; margin-bottom: 8px; }
.wd-pick label { position: relative; }
.wd-pick input { position: absolute; opacity: 0; }
.wd-pick span { display: inline-block; width: 30px; height: 30px; line-height: 30px; text-align: center; border-radius: 50%; border: 1px solid var(--line); cursor: pointer; background: var(--panel); }
.wd-pick input:checked + span { background: var(--accent); color: #fff; border-color: var(--accent); }
.repeat-end { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.repeat-end input[type=number] { width: 80px; }
.repeat-end .unit { color: var(--muted); }
#evRepeatPreview { margin-bottom: 8px; }
.tpl-preview { font-size: 12px; margin: -4px 0 12px; display: flex; flex-direction: column; gap: 4px; }
.tpl-preview:empty { display: none; }
.tpl-preview .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pill { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; }
.pill.done { text-decoration: line-through; color: var(--muted); }
.del-q { align-self: center; color: var(--muted); font-size: 13px; }

.edit-list { list-style: none; margin: 0 0 4px; padding: 0; }
.edit-list li { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.edit-list .el-title { flex: 1; padding: 4px 8px; }
.edit-list li.done .el-title { text-decoration: line-through; color: var(--muted); }
.edit-list .el-del { border: none; background: none; color: var(--muted); }
.edit-list .el-del:hover { color: var(--danger); }
.edit-add { padding: 4px 8px; border-style: dashed !important; }

/* テンプレート一覧 */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.page-head h2 { margin: 0; font-size: 18px; }
.tpl-card {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: 8px; padding: 12px 14px; margin-top: 12px;
}
.tpl-card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tpl-card-head b { font-size: 15px; }
.tpl-card-head .meta { color: var(--muted); font-size: 12px; }
.tpl-card-head .acts { margin-left: auto; display: flex; gap: 6px; }
.tpl-card-body { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.tpl-card-body .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tpl-card-body .muted { color: var(--muted); }

/* =========================================================
 * todo の階層（親 → 子 → 孫）
 * ======================================================= */
.todo.d1 { margin-left: 16px; }
.todo.d2 { margin-left: 32px; }
.todo.d1, .todo.d2 { position: relative; }
.todo.d1::before, .todo.d2::before {
  content: ""; position: absolute; left: -9px; top: 0; bottom: 50%; width: 7px;
  border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); border-bottom-left-radius: 4px;
}
.ev-todos .todo.d1 { margin-left: 12px; }
.ev-todos .todo.d2 { margin-left: 24px; }
.group .todo.d1, .group .todo.d2 { margin-left: 0; border-top-style: dashed; }
.group .todo.d1 { padding-left: 34px; }
.group .todo.d2 { padding-left: 58px; }
.group .todo.d1::before { left: 18px; }
.group .todo.d2::before { left: 42px; }
.group .todo.d1 .t-title, .group .todo.d2 .t-title { font-size: 13px; }

.sub-add { padding: 1px 2px; }
.sub-add-form { flex: 1; margin: 0; }
.sub-add input { width: 100%; font-size: 12px; padding: 2px 6px; border-style: dashed; }
.group .sub-add input { font-size: 13px; padding: 4px 8px; }

.pill-sub { color: var(--muted); margin-right: 2px; }

.edit-list li.d1 { margin-left: 22px; }
.edit-list li.d2 { margin-left: 44px; }
.el-shift { border: none; background: none; color: var(--muted); padding: 0 2px; font-size: 12px; }
.el-shift:hover { color: var(--accent); background: none; }

.todo-new { flex-wrap: wrap; }
.todo-new select { flex: none; }
.todo-new select[name=target] { max-width: 280px; }
.todo-new-hint { margin: 6px 2px 0; }

/* =========================================================
 * カレンダーをすっきり：予定の枠は表示中心、操作は詳細パネルで
 * ======================================================= */
.cal-main { flex: 1; min-height: 0; display: flex; }
.cal-main.panel-left { flex-direction: row-reverse; }
#calBody { flex: 1; min-width: 0; min-height: 0; }
#calBody > * { height: 100%; }

/* 予定ボックス：ホバーで広がらない・入力欄なし */
.ev, .ev:hover, .ev:focus-within {
  height: var(--h); overflow: hidden; z-index: 10;
  background: color-mix(in srgb, var(--c) 14%, var(--panel));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 28%, transparent);
  cursor: pointer;
}
.ev:hover { background: color-mix(in srgb, var(--c) 22%, var(--panel)); }
.ev.selected {
  z-index: 21; background: color-mix(in srgb, var(--c) 26%, var(--panel));
  box-shadow: 0 0 0 2px var(--c), var(--shadow);
}
.ev::after { /* 入りきらない todo をふわっと隠す */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 10px; pointer-events: none;
  background: linear-gradient(transparent, color-mix(in srgb, var(--c) 14%, var(--panel)));
}
.ev-head { cursor: pointer; }
.ev-todos { list-style: none; margin: 0; padding: 0 6px 2px; font-size: 11px; }
.ftodo { display: flex; align-items: center; gap: 4px; min-height: 17px; line-height: 1.25; color: var(--text); }
.ftodo input { margin: 0; width: 12px; height: 12px; flex: none; cursor: pointer; accent-color: var(--c); }
.ftodo .f-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ftodo.done .f-title { text-decoration: line-through; color: var(--muted); }
.ftodo.d1 { padding-left: 12px; }
.ftodo.d2 { padding-left: 24px; }
.m-ev.selected, .ad-ev.selected { box-shadow: 0 0 0 2px var(--c); }
.m-ev.timed.selected { background: color-mix(in srgb, var(--c) 18%, transparent); }

/* ---------- 詳細パネル ---------- */
.ev-panel {
  width: 400px; flex: none; overflow: auto; background: var(--panel);
  border-left: 1px solid var(--line); display: flex; flex-direction: column;
}
.panel-left .ev-panel { border-left: none; border-right: 1px solid var(--line); }
.pn-head {
  display: flex; align-items: flex-start; gap: 6px; padding: 16px 14px 12px 18px;
  border-top: 5px solid var(--c); background: color-mix(in srgb, var(--c) 9%, var(--panel));
}
.pn-titles { flex: 1; min-width: 0; }
.pn-title { margin: 0; font-size: 19px; line-height: 1.35; cursor: text; overflow-wrap: anywhere; border-radius: 4px; }
.pn-title:hover { background: rgba(127, 127, 127, .12); }
.pn-title-edit { width: 100%; font-size: 18px; font-weight: 600; }
.pn-when { margin-top: 4px; color: var(--muted); font-size: 13px; }
.pn-icon { border: none; background: none; color: var(--muted); padding: 2px 8px; }
.pn-icon:hover { color: var(--text); background: rgba(127, 127, 127, .14); }
.pn-tpl { padding: 8px 18px 0; font-size: 12px; color: var(--muted); }
.pn-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.pn-actions button { font-size: 12px; }
.pn-memo { padding: 10px 18px; font-size: 13px; white-space: pre-wrap; border-bottom: 1px solid var(--line); color: var(--muted); }
.pn-section { padding: 14px 18px 24px; }
.pn-sec-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.pn-sec-head h3 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.pn-count { font-size: 12px; color: var(--muted); }
.pn-progress { height: 4px; border-radius: 2px; background: var(--line-soft); margin-bottom: 12px; overflow: hidden; }
.pn-progress span { display: block; height: 100%; background: #22a06b; border-radius: 2px; transition: width .2s; }
.pn-add { margin-bottom: 4px; }
.pn-kind-hint { margin: 2px 2px 8px; font-size: 11px; }
.pn-todos { margin-top: 8px; }
.pn-todos .todo { padding: 6px 4px; font-size: 14px; border-radius: 6px; }
.pn-todos .todo input[type=checkbox] { width: 16px; height: 16px; }
.pn-todos .todo.d1, .pn-todos .todo.d2 { font-size: 13px; }
.pn-todos .t-btn { visibility: visible; opacity: .35; font-size: 14px; }
.pn-todos .todo:hover .t-btn { opacity: 1; }
.pn-todos .sub-add input { font-size: 13px; padding: 4px 8px; }
.pn-empty { padding: 8px 4px; }
.pn-help { margin-top: 14px; font-size: 11px; }

@media (max-width: 900px) {
  .ev-panel {
    position: fixed; top: 0; bottom: 0; right: 0; z-index: 90; width: min(420px, 100vw);
    box-shadow: var(--shadow); border-left: 1px solid var(--line);
  }
  .panel-left .ev-panel { right: auto; left: 0; }
}

/* 予定ボックスの見出し：1行目＝タイトル＋進捗、2行目＝時刻（狭い列でもタイトルが潰れない） */
.ev-head { flex-wrap: wrap; row-gap: 0; align-items: center; padding: 3px 6px 2px; }
.ev-title { flex: 1 1 0; min-width: 2em; }
.ev-time { order: 3; flex-basis: 100%; font-size: 10.5px; line-height: 1.2; }
.ev-tpl { order: 2; font-size: 9px; opacity: .7; }
.ev .prog { order: 2; }
/* パネルを開いても横スクロールが出にくいように列の最小幅を控えめに */
.tg-inner { min-width: calc(var(--gutter) + var(--n) * 96px); }

/* =========================================================
 * 予定は全体を予定の色で塗る（左端だけの色分けをやめる）
 * ======================================================= */
.ev, .ev:hover, .ev:focus-within {
  background: var(--c); color: #fff;
  border-left: none; border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}
.ev:hover { filter: brightness(1.06); }
.ev.selected { background: var(--c); box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--c), var(--shadow); }
.ev::after { background: linear-gradient(transparent, var(--c)); }
.ev .ev-time { color: rgba(255, 255, 255, .85); }
.ev .ev-tpl { color: #fff; opacity: .85; font-size: 12px; font-weight: 700; }
.ev .prog { background: rgba(255, 255, 255, .28); color: #fff; }
.ev .prog.complete { background: rgba(255, 255, 255, .9); color: var(--c); }
.ev .ftodo { color: #fff; }
.ev .ftodo input { accent-color: #fff; }
.ev .ftodo.done .f-title { color: rgba(255, 255, 255, .7); }
.ev .ev-resize, .ev:hover .ev-resize { background: none; }

/* 月表示の時間付き予定も同じく塗りつぶし */
.m-ev.timed { background: var(--c); color: #fff; }
.m-ev.timed::before { display: none; }
.m-ev.timed .tm { color: rgba(255, 255, 255, .85); }
.m-ev.timed .prog, .m-ev.allday .prog { background: rgba(255, 255, 255, .28); color: #fff; }
.m-ev.selected, .m-ev.timed.selected, .ad-ev.selected { background: var(--c); box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--c); }

/* =========================================================
 * Todo タブ：今日・明日・今週をはっきり分ける
 * ======================================================= */
.group { --g: var(--muted); margin-top: 22px; }
.group.g-over     { --g: var(--danger); }
.group.g-today    { --g: #3d6df2; }
.group.g-tomorrow { --g: #1a9b8a; }
.group.g-week     { --g: #8e5cf7; }
.group.g-later    { --g: #6b7280; }
.group h3 {
  display: flex; align-items: baseline; gap: 10px; margin: 0 0 6px; padding: 0 2px;
  font-size: 13px; color: var(--g); font-weight: 700;
}
.group h3 .g-name { font-size: 15px; letter-spacing: .02em; }
.group.g-today h3 .g-name { font-size: 17px; }
.group h3 .g-date { color: var(--muted); font-weight: 500; font-size: 12px; }
.group h3 .g-count {
  margin-left: auto; font-size: 11px; font-weight: 600; color: #fff; background: var(--g);
  border-radius: 10px; padding: 0 8px; line-height: 18px;
}
.group .todo-list { border-left: 4px solid var(--g); }
.group.g-today .todo-list { box-shadow: 0 2px 10px color-mix(in srgb, var(--g) 18%, transparent); }
.group.g-done .todo-list, .group.g-nodate .todo-list, .group.g-later .todo-list { border-left-width: 1px; }
.g-empty {
  border: 1px dashed var(--line); border-left: 4px solid color-mix(in srgb, var(--g) 45%, transparent);
  border-radius: 8px; padding: 9px 12px; font-size: 12px; color: var(--muted);
}
.group.g-past { --g: #9a6b3f; }
.group.g-yday { --g: #1a9b8a; }
.group.g-past .todo-list { border-left-width: 1px; }
.t-doneat { flex: none; font-size: 11px; color: var(--muted); }

/* =========================================================
 * テンプレートの集計（右端）とアーカイブ
 * ======================================================= */
.tpl-card { display: flex; gap: 16px; align-items: stretch; }
.tpl-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.tpl-main .tpl-card-body { margin-top: 0; }
.tpl-main .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.tpl-main .acts button { font-size: 12px; }
.tpl-stats {
  flex: none; width: 150px; display: flex; flex-direction: column; justify-content: center; gap: 12px;
  padding-left: 16px; border-left: 1px solid var(--line);
}
.tpl-stats .st { display: flex; flex-direction: column; gap: 2px; }
.st-label { font-size: 11px; color: var(--muted); }
.st-val { font-size: 20px; font-weight: 700; line-height: 1.2; color: var(--c); font-variant-numeric: tabular-nums; }
.st-val small { font-size: 12px; font-weight: 500; color: var(--muted); }
.st-sub { font-size: 11px; color: var(--muted); }
.st-bar { display: block; height: 4px; border-radius: 2px; background: var(--line-soft); overflow: hidden; margin-top: 3px; }
.st-bar span { display: block; height: 100%; background: var(--c); }

.tpl-archive { margin-top: 28px; }
.tpl-archive summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; }
.tpl-archive .hint { margin: 6px 0 0; }
.tpl-card.archived { opacity: .75; border-left-style: dashed; }

@media (max-width: 720px) {
  .tpl-card { flex-direction: column; }
  .tpl-stats { width: auto; flex-direction: row; padding-left: 0; padding-top: 10px; border-left: none; border-top: 1px solid var(--line); }
  .tpl-stats .st { flex: 1; }
}

/* =========================================================
 * カレンダー上の期限todo：簡易表示（操作はその日のtodoパネル）
 * ======================================================= */
.due-list { list-style: none; margin: 2px 0 0; padding: 0; }
.due-todo {
  font-size: 12px; min-height: 20px; padding: 1px 6px; margin: 1px 0; border-radius: 4px; cursor: pointer;
  background: var(--panel2); border: 1px solid var(--line-soft);
}
.due-todo:hover { border-color: var(--line); background: var(--accent-soft); }
.due-todo input { accent-color: var(--accent); }
.sub-count { margin-left: auto; flex: none; font-size: 10px; color: var(--muted); padding-left: 4px; }

/* 週・日表示の終日の行：クリックでその日のtodoパネル */
.tg-ad { cursor: pointer; position: relative; min-height: 26px; }
.tg-ad:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.tg-ad:hover::after {
  content: "＋ todo"; position: absolute; right: 4px; bottom: 2px; font-size: 10px; color: var(--accent); pointer-events: none;
}
.tg-ad.day-sel, .m-cell.day-sel { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }

/* 月表示：日付の横に「＋ todo」（ホバーで表示） */
.m-top { display: flex; align-items: center; justify-content: space-between; }
.m-addtodo {
  border: none; background: none; color: var(--accent); font-size: 10px; padding: 0 4px; visibility: hidden;
}
.m-cell:hover .m-addtodo, .m-cell.day-sel .m-addtodo { visibility: visible; }
.m-items .due-todo { font-size: 11px; min-height: 18px; }

/* その日のtodoパネル */
.pn-title-static { margin: 0; font-size: 19px; display: flex; align-items: baseline; gap: 8px; }
.pn-rel { font-size: 12px; font-weight: 600; color: #fff; background: var(--accent); border-radius: 10px; padding: 1px 8px; }
.pn-day-events { border-top: 1px solid var(--line); }
.pn-ev {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; margin-bottom: 6px;
  background: var(--c); color: #fff; border: none; border-radius: 6px; padding: 6px 10px;
}
.pn-ev:hover { filter: brightness(1.07); background: var(--c); }
.pn-ev-time { font-size: 12px; opacity: .85; flex: none; }
.pn-ev-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pn-ev .prog { background: rgba(255, 255, 255, .28); color: #fff; }
.pn-todos .todo.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { background: color-mix(in srgb, var(--accent) 22%, transparent); } 100% { background: transparent; } }

/* =========================================================
 * プリセット
 * ======================================================= */
.preset-sel { font-size: 12px; padding: 4px 6px; max-width: 100%; color: var(--muted); }
.preset-sel:not(:disabled):hover { color: var(--text); border-color: var(--accent); }
.todo-new .preset-sel { flex: none; align-self: stretch; }
.pn-preset { margin: 6px 0 2px; }
.pn-preset .preset-sel { width: 100%; }

.batch-list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 2px; }
.batch-chip {
  display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 4px 10px; border-radius: 8px;
  background: var(--panel2); border: 1px dashed var(--line);
}
.batch-chip small { color: var(--muted); }
.batch-chip .link { margin-left: auto; }
.danger-link { color: var(--danger) !important; font-size: 12px; }

.preset-box { margin-top: 4px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.preset-box-head { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.preset-from { font-size: 12px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.preset-reg { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.preset-reg select { flex: 1; min-width: 160px; }
.preset-reg input { flex: 1; min-width: 140px; }
.preset-reg .chk { margin: 0; font-size: 12px; }
.preset-box .hint { margin: 8px 0 0; font-size: 11px; }

.preset-head { margin-top: 32px; }
.preset-card { border-left-color: var(--muted); }
.preset-card .meta { color: var(--muted); font-size: 12px; }
.tpl-preset-sel { margin-top: 4px; font-size: 12px; padding: 4px 6px; color: var(--muted); }
.tpl-preset-sel:not(:disabled):hover { color: var(--text); border-color: var(--accent); }

/* =====================================================================
 * デザイン整理（文字で伝えない）
 *   A 状態は色と形（アイコン・進捗リング・日付チップ）
 *   B 常設の説明文をやめて ? ヘルプへ
 *   C 二次的な操作は ⋯ メニューへ
 *   D 枠線を減らし、余白と背景でまとめる
 * ===================================================================== */

/* ---------- 部品：アイコン ---------- */
.ic { width: 1em; height: 1em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.125em; }
.c-repeat { color: #3d6df2; }
.c-once   { color: #c27c0e; }
@media (prefers-color-scheme: dark) { .c-repeat { color: #8fb0ff; } .c-once { color: #f0b54a; } }

/* ---------- 部品：進捗リング ---------- */
.ring { display: inline-flex; width: var(--s); height: var(--s); flex: none; vertical-align: middle; }
.ring svg { width: 100%; height: 100%; }
.ring-bg { fill: none; stroke: color-mix(in srgb, currentColor 18%, transparent); stroke-width: 2.6; }
.ring-fg { fill: none; stroke: #22a06b; stroke-width: 2.6; stroke-linecap: round; transition: stroke-dasharray .3s; }
.ring.complete .ring-bg { fill: #22a06b; stroke: #22a06b; }
.ring-check { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* 色付きの予定の上では白で */
.ev .ring-bg, .m-ev .ring-bg, .ad-ev .ring-bg, .pn-ev .ring-bg { stroke: rgba(255, 255, 255, .38); }
.ev .ring-fg, .m-ev .ring-fg, .ad-ev .ring-fg, .pn-ev .ring-fg { stroke: #fff; }
.ev .ring.complete .ring-bg, .m-ev .ring.complete .ring-bg, .ad-ev .ring.complete .ring-bg, .pn-ev .ring.complete .ring-bg { fill: #fff; stroke: #fff; }
.ev .ring-check, .m-ev .ring-check, .ad-ev .ring-check, .pn-ev .ring-check { stroke: var(--c); }
.ev-head .ring, .m-ev .ring, .ad-ev .ring { margin-left: auto; }

/* ---------- 部品：⋯ メニュー と ? ヘルプ ---------- */
.menu {
  position: fixed; z-index: 300; min-width: 180px; max-width: 300px; padding: 6px;
  background: var(--panel); border-radius: 10px; box-shadow: 0 8px 30px rgba(15, 23, 42, .22), 0 0 0 1px var(--line);
  display: flex; flex-direction: column; gap: 1px; animation: menu-in .12s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: none; background: none; border-radius: 6px; padding: 7px 10px; font-size: 13px;
}
.menu button .ic { color: var(--muted); font-size: 15px; }
.menu button:hover { background: var(--accent-soft); }
.menu button.danger, .menu button.danger .ic { color: var(--danger); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 2px; }
.menu-text { margin: 4px 8px 6px; font-size: 12px; color: var(--muted); line-height: 1.7; }
.menu-help { max-width: 320px; }
.menu-help .menu-text { color: var(--text); font-size: 12.5px; }
.menu-help .ic { color: var(--muted); }
.help-btn {
  border: none; background: none; padding: 2px; margin-left: 4px; color: var(--muted); opacity: .55;
  display: inline-flex; align-items: center; font-size: 15px; line-height: 1; border-radius: 50%; vertical-align: middle;
}
.help-btn:hover { opacity: 1; color: var(--accent); background: none; }

/* ---------- 共通：todo の行 ---------- */
.t-btn { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border-radius: 6px; font-size: 15px; }
.t-btn:hover { background: rgba(127, 127, 127, .14); }
.t-kind-ic { display: inline-flex; flex: none; font-size: 14px; }
.t-memo { display: inline-flex; flex: none; color: var(--muted); font-size: 13px; }
.t-due { font-size: 11px; color: var(--muted); background: var(--panel2); border-radius: 10px; padding: 1px 7px; }
.t-due.over { color: #fff; background: var(--danger); font-weight: 600; }

/* ---------- カレンダー：テンプレートバー ---------- */
.tpl-bar .lbl { display: inline-flex; color: var(--muted); font-size: 15px; margin-right: 2px; }
.tpl-chip small { display: none; }
.tpl-bar .ghost-btn { display: inline-flex; align-items: center; gap: 4px; border-radius: 14px; }

/* ---------- 詳細パネル（D：区切り線をなくし余白でまとめる） ---------- */
.pn-head { border-top-width: 4px; padding: 16px 10px 14px 18px; gap: 2px; }
.pn-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border: none; background: none; border-radius: 8px; color: var(--muted); font-size: 17px; padding: 0; flex: none;
}
.pn-icon:hover { background: rgba(127, 127, 127, .14); color: var(--text); }
.pn-when { display: flex; align-items: center; gap: 6px; }
.pn-when .ic { font-size: 13px; }
.pn-tpl-chip {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; padding: 2px 10px 2px 8px; font-size: 12px;
  border: none; border-radius: 12px; background: color-mix(in srgb, var(--c, var(--accent)) 16%, var(--panel)); color: var(--text);
}
.pn-tpl-chip .ic { color: var(--c, var(--accent)); }
.pn-memo { display: flex; gap: 8px; align-items: flex-start; border-bottom: none; padding: 12px 18px 0; }
.pn-memo .ic { margin-top: 3px; }
.pn-section { padding: 16px 18px 20px; }
.pn-sec-head { justify-content: flex-start; align-items: center; gap: 8px; margin-bottom: 10px; }
.pn-sec-head h3 { font-size: 14px; color: var(--text); }
.pn-sec-head .spacer { flex: 1; }
.pn-sec-ic { display: inline-flex; color: var(--muted); font-size: 18px; }
.pn-count { font-size: 13px; font-variant-numeric: tabular-nums; }
.pn-progress, .pn-kind-hint, .pn-help, .pn-preset { display: none; }

/* 追加欄：＋アイコン＋入力＋プリセットボタン（1行） */
.pn-add {
  display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; margin-bottom: 6px;
  background: var(--panel2); border-radius: 8px; border: 1px solid transparent;
}
.pn-add:focus-within { border-color: var(--accent); background: var(--panel); }
.pn-add-ic { display: inline-flex; color: var(--accent); font-size: 16px; }
.pn-add input { flex: 1; border: none !important; background: transparent !important; outline: none !important; padding: 5px 2px; font-size: 14px; }
.pn-preset-btn, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0;
  border: none; background: none; border-radius: 6px; color: var(--muted); font-size: 16px; flex: none;
}
.pn-preset-btn:hover:not(:disabled), .icon-btn:hover { color: var(--accent); background: var(--accent-soft); }
.pn-preset-btn:disabled { opacity: .35; cursor: default; }

/* 種類の切替（この回 / 毎回 / 一度） */
.kind-pick { display: inline-flex; gap: 2px; padding: 2px; margin-bottom: 8px; background: var(--panel2); border-radius: 8px; }
.kp {
  display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 26px; padding: 0 8px;
  border: none; background: none; border-radius: 6px; font-size: 15px; color: var(--muted);
}
.kp.c-repeat, .kp.c-once { color: var(--muted); }
.kp-txt { font-size: 12px; }
.kp.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); color: var(--text); }
.kp.on.c-repeat { color: #3d6df2; }
.kp.on.c-once { color: #c27c0e; }

/* プリセットのまとまり */
.batch-list { margin: 4px 0 6px; }
.batch-chip { border: none; background: var(--panel2); padding: 4px 4px 4px 10px; gap: 8px; }
.batch-chip > .ic { color: var(--muted); }
.bc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bc-del { visibility: visible; color: var(--muted); }
.bc-del:hover { color: var(--danger); }

.pn-todos .todo { padding: 5px 4px; }
.pn-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 0 10px; color: var(--muted); font-size: 12px; }
.pn-empty .ic { font-size: 28px; opacity: .45; }
.pn-day-events { border-top: none; padding-top: 4px; }
.pn-day-ic { color: var(--accent); margin-right: 2px; }
.pn-title-static { align-items: center; }

/* ---------- Todo タブ ---------- */
.todo-new { align-items: stretch; }
.todo-toolbar { gap: 6px; }
.group { margin-top: 26px; }
.group h3 { align-items: center; }
.group h3 .g-count { margin-left: 6px; }
.group .todo-list { border: none; border-left: 3px solid var(--g); border-radius: 0 10px 10px 0; box-shadow: 0 1px 2px rgba(15, 23, 42, .05); }
.group.g-today .todo-list { box-shadow: 0 4px 16px color-mix(in srgb, var(--g) 16%, transparent); }
.group .todo { border-top: none; padding: 8px 10px; }
.group .todo + .todo { box-shadow: inset 0 1px 0 var(--line-soft); }
.group.is-empty { opacity: .45; margin-top: 18px; }
.group.is-empty h3 { margin: 0; }
.group.is-empty h3 .g-name { font-size: 13px; }
.group.g-today.is-empty h3 .g-name { font-size: 15px; }

.t-ev {
  display: inline-flex; align-items: center; gap: 5px; background: none; color: var(--muted); font-size: 12px; padding: 1px 6px; border-radius: 6px;
}
.t-ev:hover { background: rgba(127, 127, 127, .12); color: var(--text); }
.t-ev i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.t-ev .ic { color: var(--c); }
.t-ev small { opacity: .8; }

/* 期限の日付チップ（押すと日付選択） */
.t-datechip {
  position: relative; display: inline-flex; align-items: center; gap: 4px; flex: none; cursor: pointer;
  font-size: 12px; color: var(--accent); padding: 2px 8px; border-radius: 10px; background: var(--accent-soft);
}
.t-datechip .ic { font-size: 12px; }
.t-datechip.over { background: var(--danger); color: #fff; }
.t-datechip.empty { background: none; color: var(--muted); visibility: hidden; padding: 2px 5px; }
.todo:hover .t-datechip.empty, .t-datechip.empty:focus-within { visibility: visible; }
.t-datechip input { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.todo.done .t-datechip { background: none; color: var(--muted); }
.t-doneat { display: inline-flex; align-items: center; gap: 3px; }
.t-doneat .ic { color: #22a06b; }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 0; color: var(--muted); font-size: 13px; }
.empty-state .ic { font-size: 34px; opacity: .4; }

/* ---------- テンプレートタブ ---------- */
.page-head h2 { display: flex; align-items: center; gap: 8px; }
.ph-ic { display: inline-flex; color: var(--muted); }
.preset-head { margin-top: 40px; }
.tpl-card { border: none; border-left: 4px solid var(--c); box-shadow: 0 1px 3px rgba(15, 23, 42, .07); padding: 14px 16px; }
.tpl-card-head { gap: 12px; }
.tc-title {
  display: inline-flex; align-items: center; gap: 6px; border: none; background: none; padding: 0;
  font-size: 16px; font-weight: 700; color: var(--text); text-align: left;
}
.tc-title:hover { color: var(--accent); background: none; }
.tc-title .ic { color: var(--muted); }
.tc-next { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.tc-next small { margin-left: 4px; padding: 0 6px; border-radius: 8px; background: var(--panel2); }
.tpl-card-body .row { gap: 5px; }
.pill { border: none; background: var(--panel2); padding: 1px 9px; }
.pill.sub { background: none; padding-left: 2px; color: var(--muted); }
.pill.sub::before { content: "└ "; opacity: .6; }
.tpl-main .acts { gap: 4px; align-items: center; }
.tc-primary {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 5px 12px; border: none; border-radius: 8px;
  background: color-mix(in srgb, var(--c) 14%, var(--panel)); color: var(--text); font-weight: 600;
}
.tc-primary .ic { color: var(--c); }
.tc-primary:hover { background: color-mix(in srgb, var(--c) 24%, var(--panel)); }
.tc-primary.tc-quiet { background: var(--panel2); }
.tc-more { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 28px; padding: 0; border: none; background: none; color: var(--muted); border-radius: 8px; font-size: 16px; }
.tc-more:hover { background: rgba(127, 127, 127, .14); color: var(--text); }
.tpl-stats { border-left: none; padding-left: 8px; width: 140px; gap: 14px; }
.tpl-stats .st { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.st-ic { display: inline-flex; color: var(--c); font-size: 18px; width: 20px; justify-content: center; }
.st-val { font-size: 18px; }
.st-sub { width: 100%; padding-left: 28px; margin-top: -4px; }
.tpl-archive summary { display: flex; align-items: center; gap: 6px; list-style: none; }
.tpl-archive summary::-webkit-details-marker { display: none; }
.tpl-archive summary small { padding: 0 7px; border-radius: 8px; background: var(--panel2); }
.preset-card { border-left-color: var(--line); }
.tc-count { font-size: 11px; color: var(--muted); background: var(--panel2); border-radius: 10px; padding: 0 8px; line-height: 18px; }

/* ---------- ダイアログ ---------- */
.dlg h2 { display: flex; align-items: center; }
.lbl-ic { display: inline-flex !important; align-items: center; gap: 6px; font-size: 13px !important; color: var(--text) !important; font-weight: 600; }
.preset-box { border: none; background: var(--panel2); }
.preset-box-head { display: flex; align-items: center; gap: 6px; }
.group .todo.d1, .group .todo.d2 { border-top: none; }
.t-datechip.quiet { background: none; color: var(--muted); visibility: hidden; padding: 2px 5px; }
.todo:hover .t-datechip.quiet { visibility: visible; }
.kind-pick .help-btn { margin: 0 2px 0 4px; }

/* =========================================================
 * スマホ・タブレット（指での操作・狭い画面・ホーム画面アプリ）
 * ======================================================= */
html, body { height: 100dvh; }
.tab-ic { display: none; }
.tab-ic .ic, .tab-ic svg { width: 20px; height: 20px; }

/* 指で操作する端末：ホバーがないので、隠していたボタンを薄く常に出す */
@media (hover: none) {
  .t-btn { visibility: visible; opacity: .4; }
  .todo:focus-within .t-btn { opacity: 1; }
  .t-datechip.empty, .t-datechip.quiet { visibility: visible; opacity: .5; }
  .m-addtodo { display: none; }
  .tg-ad .add-todo input { opacity: 1; }
}
/* 指での操作：長押しのメニューや文字選択を出さない・押せる大きさを確保 */
@media (pointer: coarse) {
  #calBody .ev, #calBody .ev-head, .tpl-chip, .tg-col, .m-cell { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .tpl-chip { touch-action: auto; }
  .ev-resize { height: 14px; }
  .ev-resize::after {
    content: ""; position: absolute; left: 50%; bottom: 4px; width: 22px; height: 3px; margin-left: -11px;
    border-radius: 2px; background: rgba(255, 255, 255, .7);
  }
  .todo input[type=checkbox], .pn-todos .todo input[type=checkbox] { width: 20px; height: 20px; }
  .ev-todos .todo input[type=checkbox], .ftodo input[type=checkbox] { width: 15px; height: 15px; }
  .t-btn { padding: 4px 8px; font-size: 15px; }
  .pn-icon { width: 40px; height: 40px; }
  .seg button { padding: 7px 13px; }
}
.ev.dragging { box-shadow: 0 8px 24px rgba(0, 0, 0, .3); z-index: 20; }

/* ---------- スマホ（幅 720px 以下） ---------- */
@media (max-width: 720px) {
  :root { --gutter: 38px; --tabbar: 58px; }
  /* iPhone で入力欄を押したときに画面が拡大されないよう 16px 以上にする */
  input, select, textarea { font-size: 16px; }
  .add-todo input, .ev-todos input { font-size: 16px; }

  /* 上のバー：1行にまとめる（カレンダー以外のタブでは畳む） */
  .topbar {
    flex-wrap: nowrap; gap: 6px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
    padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right));
  }
  /* 上のバーの中に下のタブバーがあるので、バー自体は隠さず中身と余白だけを畳む */
  body:not([data-tab=calendar]) .topbar { padding: 0; border: none; min-height: 0; }
  body:not([data-tab=calendar]) .cal-ctrl { display: none; }
  body:not([data-tab=calendar]) main { padding-top: env(safe-area-inset-top); }
  .brand { display: none; }
  .cal-ctrl { flex-wrap: nowrap; gap: 4px; min-width: 0; }
  .cal-ctrl h1 { order: -1; flex: 1; min-width: 0; margin: 0 4px 0 2px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #prevBtn, #nextBtn { padding: 5px 8px; }
  #todayBtn { padding: 5px 9px; }
  #zoomSeg { display: none !important; }
  .seg button { padding: 6px 10px; }

  /* 予定の追加は右下の丸いボタン */
  #newEventBtn {
    position: fixed; z-index: 60; right: max(16px, env(safe-area-inset-right));
    bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom));
    width: 56px; height: 56px; border-radius: 50%; padding: 0; margin: 0;
    font-size: 26px; line-height: 1; box-shadow: 0 6px 18px rgba(61, 109, 242, .45);
  }
  #newEventBtn .nb-lbl { display: none; }

  /* タブは画面下のバー */
  .tabs {
    position: fixed; z-index: 70; left: 0; right: 0; bottom: 0;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 -1px 0 var(--line); gap: 0;
  }
  .tabs button {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border-radius: 0; padding: 4px 0 2px; font-size: 10.5px;
  }
  .tabs button.active { background: none; }
  .tabs .tab-ic { display: block; line-height: 0; }
  .tabs .badge { position: absolute; top: 4px; left: calc(50% + 6px); font-size: 10px; min-width: 16px; line-height: 16px; padding: 0 4px; }
  main { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(var(--tabbar) + 20px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }

  /* テンプレートバー：横にスクロール */
  .tpl-bar { flex-wrap: nowrap; overflow-x: auto; padding: 6px 10px; scrollbar-width: none; }
  .tpl-bar::-webkit-scrollbar { display: none; }
  .tpl-chip, .tpl-bar .ghost-btn { flex: none; }

  /* 週表示：7日を画面幅に収める */
  .tg-inner { min-width: 0; }
  .tg-hl { right: 4px; font-size: 10px; }
  .tg-ad-label { font-size: 10px; padding-right: 3px; }
  .tg-dh { padding: 2px 0; }
  .tg-dh button { flex-direction: column; align-items: center; gap: 0; padding: 2px 0; }
  .tg-dh .wd { font-size: 10px; }
  .tg-dh .dn { font-size: 16px; }
  .tg-ad { padding: 2px 1px; }
  .ev-head { padding: 2px 3px 1px; }
  .ev-title { font-size: 11px; }
  .ev-tpl, .ev .prog { display: none; }
  .view-week .ev-time, .view-week .ev-todos { display: none; }
  .view-week .ev-title { white-space: normal; overflow-wrap: anywhere; line-height: 1.25; }

  /* 月表示：マスを詰める */
  .m-cell { padding: 2px 1px; }
  .m-ev { font-size: 10px; padding: 1px 3px; }
  .m-ev .tm { display: none; }

  /* 詳細パネル：下から出るシート */
  .ev-panel, .panel-left .ev-panel {
    position: fixed; z-index: 80; left: 0; right: 0; top: auto; bottom: 0; width: auto;
    height: min(78dvh, 640px); border: none; border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(15, 23, 42, .25), 0 0 0 100vmax rgba(10, 14, 22, .25);
    padding-bottom: env(safe-area-inset-bottom); overflow: auto; overscroll-behavior: contain;
    animation: sheet-up .2s ease-out;
  }
  .ev-panel .pn-head { position: sticky; top: 0; z-index: 2; border-top: none; padding-top: 22px; border-radius: 16px 16px 0 0; }
  .ev-panel .pn-head::before {
    content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px;
    border-radius: 3px; background: color-mix(in srgb, var(--c) 45%, var(--muted));
  }
  [data-pn=side] { display: none !important; }

  /* Todo タブ */
  .todo-page { padding: 14px 12px 90px; }
  .todo-new input[name=title] { flex: 1 1 100%; }
  .todo-new select[name=target] { max-width: none; flex: 1; }
  .group .todo { flex-wrap: wrap; row-gap: 2px; padding: 8px 6px 8px 8px; }
  .group .t-title { flex: 1 1 120px; }
  .t-ev { max-width: 100%; }

  /* ダイアログ：画面いっぱい近くまで使う */
  .dlg { width: calc(100vw - 16px); max-width: none; }
  .dlg-body { padding: 16px 14px 6px; max-height: calc(100dvh - 120px); }
  .dlg-foot { padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .page-head h2 { font-size: 18px; }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* スマホの Todo タブ：1行目＝チェック・タイトル・ボタン、2行目＝予定や期限のチップ */
@media (max-width: 720px) {
  .group .todo { column-gap: 2px; }
  .group .todo > * { order: 1; }
  .group .todo > .t-title { flex: 1 1 0; }
  .group .todo > .t-btn { order: 2; padding: 4px 6px; }
  .group .todo::after { content: ""; order: 3; flex-basis: 100%; }
  .group .todo::before { content: ""; order: 4; flex: none; width: 24px; }
  .group .todo > .t-ev, .group .todo > .t-datechip, .group .todo > .t-doneat { order: 5; }
  .group .todo > .t-datechip.empty, .group .todo > .t-datechip.quiet { display: none; }
}

/* タブレット（iPad の縦など）：上のバーを詰める */
@media (min-width: 721px) and (max-width: 1100px) {
  .brand { display: none; }
  .topbar { gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .cal-ctrl { flex-wrap: nowrap; min-width: 0; }
  .cal-ctrl h1 { min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
  .tabs button { padding: 6px 9px; }
  .ev-panel { padding-top: env(safe-area-inset-top); }
}
@media (min-width: 721px) and (max-width: 900px) {
  .tabs .tab-lbl { display: none; }
  .tabs .tab-ic { display: inline-block; vertical-align: -4px; }
  #zoomSeg { display: none !important; }
}
/* 長さ変更のつまみは選択中の予定だけに出す */
@media (pointer: coarse) {
  .ev:not(.selected) .ev-resize::after { display: none; }
}

/* ボタン内のアイコンは押せる対象にしない（押したときは必ずボタン本体が反応する） */
button svg, button .ic, .t-datechip svg { pointer-events: none; }

/* =========================================================
 * 指で操作する端末：押す場所を大きく（誤タップを防ぐ）
 * ======================================================= */
@media (pointer: coarse) {
  /* todo の行（パネル・Todo タブ） */
  .pn-todos .todo, .group .todo { min-height: 50px; gap: 6px; }
  .pn-todos .todo input[type=checkbox], .group .todo input[type=checkbox] { width: 24px; height: 24px; margin: 0 4px; }
  .pn-todos .todo.d1, .pn-todos .todo.d2, .pn-todos .todo { font-size: 16px; }
  .pn-todos .t-title, .group .t-title { font-size: 16px; padding: 6px 0; }
  .pn-todos .t-btn, .group .t-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; padding: 0; border-radius: 10px; font-size: 20px; opacity: .6;
  }
  .pn-todos .t-btn:active, .group .t-btn:active { background: rgba(127, 127, 127, .18); opacity: 1; }
  /* 削除（×）は他のボタンから少し離す */
  .pn-todos .t-del, .group .t-del { margin-left: 6px; }
  .pn-todos .sub-add input, .group .sub-add input { font-size: 16px; padding: 10px 12px; }

  /* パネルの見出しのボタン */
  .pn-icon { width: 46px; height: 46px; font-size: 21px; border-radius: 12px; }
  .pn-icon:active { background: rgba(127, 127, 127, .18); }

  /* 追加欄・種類の切り替え */
  .pn-add { min-height: 52px; padding-left: 12px; }
  .pn-add input { font-size: 16px; padding: 10px 2px; }
  .pn-preset-btn, .icon-btn { width: 44px; height: 44px; font-size: 20px; }
  .kind-pick { gap: 4px; padding: 3px; }
  .kp { min-width: 52px; height: 42px; font-size: 18px; }
  .kp-txt { font-size: 14px; }
  .help-btn { min-width: 36px; min-height: 36px; }

  /* 上のバー・切り替え */
  .seg button { min-height: 40px; padding: 6px 12px; }
  #prevBtn, #nextBtn, #todayBtn { min-height: 40px; min-width: 40px; }
  .tpl-chip { padding: 8px 14px; font-size: 14px; }
  .tpl-bar .ghost-btn { padding: 8px 14px; }

  /* カレンダー上の期限todo */
  .due-todo { min-height: 30px; font-size: 13px; }

  /* ダイアログ */
  .dlg-foot button { min-height: 46px; padding: 8px 18px; font-size: 16px; }
  .dlg input[type=checkbox] { width: 22px; height: 22px; }
  .menu button, .menu-item { min-height: 46px; font-size: 16px; }
}
@media (pointer: coarse) and (max-width: 720px) {
  .seg button { padding: 6px 9px; }
  #todayBtn { padding: 6px 8px; }
  /* 3日表示は列が広いので、予定の文字を少し大きく */
  .view-3day .ev-title { font-size: 12.5px; }
}

/* =========================================================
 * ≡ をつかんで並べ替え
 * ======================================================= */
.t-grip {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 22px; padding: 0; margin: 0 -2px 0 -4px; border: none; background: none;
  color: var(--muted); font-size: 14px; cursor: grab; touch-action: none; opacity: 0;
}
.t-grip:hover { background: none; color: var(--text); }
.todo:hover .t-grip, .edit-list li:hover .t-grip, .todo:focus-within .t-grip { opacity: .55; }
.edit-list .t-grip { opacity: .4; margin: 0 2px 0 0; }
.row-dragging {
  position: relative; z-index: 5; background: var(--panel) !important; opacity: .95;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .18); border-radius: 8px;
}
.row-dragging .t-grip { opacity: 1; color: var(--accent); }
body.is-row-dragging, body.is-row-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

/* 指で操作する端末：つかみやすい大きさで常に見せる */
@media (pointer: coarse) {
  .t-grip { width: 36px; height: 44px; margin: 0 -4px 0 -8px; font-size: 20px; opacity: .45; }
  .edit-list .t-grip { width: 36px; height: 40px; margin: 0; opacity: .45; }
}
/* スマホのダイアログ下部：4つのボタンが1行に収まるように */
@media (pointer: coarse) and (max-width: 720px) {
  .dlg-foot { flex-wrap: nowrap; gap: 6px; }
  .dlg-foot button { padding: 8px 10px; font-size: 15px; white-space: nowrap; }
  .dlg-foot .spacer { flex: 1 1 0; min-width: 0; }
}

/* =========================================================
 * スマホ：テンプレートタブを大きめの表示に
 * ======================================================= */
@media (max-width: 720px) {
  #tplView .todo-page { padding: 18px 14px 100px; }

  /* 見出し（テンプレート / プリセット）と追加ボタン */
  #tplView .page-head { margin-bottom: 10px; }
  #tplView .page-head h2 { font-size: 22px; gap: 10px; }
  #tplView .page-head h2 .ph-ic { font-size: 22px; }
  #tplView .page-head > button { min-height: 44px; padding: 8px 16px; font-size: 16px; border-radius: 10px; }
  #tplView .preset-head { margin-top: 36px; }

  /* カード */
  #tplView .tpl-card { padding: 16px 16px 14px 18px; gap: 12px; border-radius: 12px; margin-bottom: 14px; }
  #tplView .tpl-main { gap: 12px; }
  #tplView .tpl-card-head { gap: 8px 12px; }
  #tplView .tc-title { font-size: 20px; line-height: 1.3; padding: 2px 0; gap: 8px; }
  #tplView .tc-title .ic { font-size: 20px; }
  #tplView .tc-next { font-size: 15px; gap: 6px; width: 100%; }
  #tplView .tc-next .ic { font-size: 16px; }
  #tplView .tc-next small { font-size: 13px; padding: 1px 8px; border-radius: 10px; }
  #tplView .tc-count { font-size: 14px; line-height: 24px; padding: 0 10px; border-radius: 12px; }

  /* 中身の todo（毎回・一度・プリセットの中身） */
  #tplView .tpl-card-body { font-size: 15px; gap: 8px; }
  #tplView .tpl-card-body .row { gap: 7px; }
  #tplView .pill { padding: 4px 12px; border-radius: 14px; line-height: 1.4; }
  #tplView .pill.sub { padding-left: 2px; }
  #tplView .t-kind-ic { font-size: 19px; margin-right: 2px; }

  /* 操作：「＋ カレンダーへ」と ⋯ */
  #tplView .tpl-main .acts { gap: 10px; margin-top: 4px; }
  #tplView .tc-primary { min-height: 46px; padding: 8px 18px; font-size: 16px; border-radius: 12px; gap: 8px; }
  #tplView .tc-primary .ic { font-size: 18px; }
  #tplView .tc-more { width: 46px; height: 46px; font-size: 22px; border-radius: 12px; }

  /* 集計（累計時間・達成todo）：カード下に横並びで大きく */
  #tplView .tpl-stats { width: auto; flex-direction: row; gap: 10px; padding: 14px 0 0; border-left: none; border-top: 1px solid var(--line-soft); }
  #tplView .tpl-stats .st { flex: 1; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  #tplView .st-ic { font-size: 24px; width: 26px; }
  #tplView .st-ic .ring { --s: 24px !important; }
  #tplView .st-val { font-size: 24px; }
  #tplView .st-val small { font-size: 15px; }
  #tplView .st-sub { font-size: 14px; width: 100%; padding-left: 34px; margin-top: -2px; }

  /* アーカイブ */
  #tplView .tpl-archive { margin-top: 24px; }
  #tplView .tpl-archive summary { font-size: 17px; gap: 10px; min-height: 44px; }
  #tplView .tpl-archive summary .ic { font-size: 20px; }
  #tplView .tpl-archive summary small { font-size: 14px; padding: 1px 9px; }
  #tplView .help-btn { font-size: 20px; }
  #tplView .empty-state { font-size: 16px; }

  /* テンプレート・プリセットの編集画面 */
  #tplDlg h2, #presetDlg h2 { font-size: 20px; }
  #tplDlg .fld > span, #presetDlg .fld > span { font-size: 14px; }
  #tplDlg .lbl-ic, #presetDlg .lbl-ic { font-size: 16px !important; }
  #tplDlg .chk, #presetDlg .chk { font-size: 16px; }
  .edit-list li { margin-bottom: 8px; gap: 2px; }
  .edit-list .el-title { font-size: 16px; padding: 9px 10px; }
  .edit-list .el-shift, .edit-list .el-del { min-width: 38px; min-height: 40px; font-size: 18px; }
  .edit-add { font-size: 16px; padding: 10px 12px; }
}

/* =========================================================
 * テンプレートタブ：タイトルの一覧 → 詳細
 * ======================================================= */
.tl-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 4px; }
.tl-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 12px 12px 16px; border: none; border-left: 4px solid var(--c); border-radius: 10px;
  background: var(--panel); box-shadow: 0 1px 3px rgba(15, 23, 42, .07); font-size: 15px;
}
.tl-row:hover { background: var(--panel); box-shadow: 0 2px 8px rgba(15, 23, 42, .12); }
.tl-row:active { background: var(--panel2); }
.tl-title { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.tl-chev { display: inline-flex; color: var(--muted); font-size: 18px; flex: none; }
.tl-ic { display: inline-flex; color: var(--muted); font-size: 18px; }
.tl-list.archived .tl-row { opacity: .7; border-left-style: dashed; }

/* 詳細 */
.td-wrap { display: flex; flex-direction: column; gap: 14px; }
.td-top { display: flex; align-items: center; }
.td-back {
  display: inline-flex; align-items: center; gap: 4px; border: none; background: none;
  color: var(--accent); font-size: 15px; padding: 6px 10px 6px 2px;
}
.td-back:hover { background: none; text-decoration: underline; }
.td-back .ic { font-size: 20px; }
.td-hero { border-left: 5px solid var(--c); padding: 2px 0 2px 14px; }
.td-title { margin: 0; font-size: 22px; line-height: 1.3; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; overflow-wrap: anywhere; }
.td-title > .ic { color: var(--muted); }
.td-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; color: var(--muted); background: var(--panel2); border-radius: 10px; padding: 2px 8px; }
.td-next { margin-top: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.td-next b { color: var(--text); font-weight: 600; }
.td-next small { padding: 1px 8px; border-radius: 10px; background: var(--panel2); }
.td-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.td-stat {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; padding: 12px 14px;
  background: var(--panel); border-radius: 12px; box-shadow: 0 1px 3px rgba(15, 23, 42, .07);
}
.td-stat .st-ic { font-size: 22px; width: 24px; }
.td-stat .st-val { font-size: 22px; color: var(--c); }
.td-stat .st-sub { width: 100%; padding-left: 32px; margin: 0; font-size: 12px; }
.td-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px;
  border: none; border-radius: 12px; font-size: 16px; font-weight: 600; color: #fff; background: var(--c);
}
.td-primary:hover { background: var(--c); filter: brightness(1.06); }
.td-primary.tc-quiet { background: var(--panel2); color: var(--text); }
.td-sec { background: var(--panel); border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 3px rgba(15, 23, 42, .07); }
.td-sec h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 14px; font-weight: 700; }
.td-sec h3 small { font-weight: 500; color: var(--muted); padding: 0 8px; border-radius: 10px; background: var(--panel2); }
.td-list { list-style: none; margin: 0; padding: 0; }
.td-list li { display: flex; align-items: center; gap: 10px; padding: 7px 2px; font-size: 15px; }
.td-list li + li { box-shadow: inset 0 1px 0 var(--line-soft); }
.td-list li > i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); opacity: .7; flex: none; margin: 0 4px; }
.td-list li.d1 { padding-left: 24px; font-size: 14px; }
.td-list li.d2 { padding-left: 46px; font-size: 14px; }
.td-list li.d1 > i, .td-list li.d2 > i { background: none; border: 1.5px solid var(--muted); width: 6px; height: 6px; }
.td-list li.done { color: var(--muted); text-decoration: line-through; }
.td-list li.done .ic { color: #22a06b; }
.td-edit {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
  border-radius: 12px; font-size: 15px; background: var(--panel);
}

/* スマホ：大きめに */
@media (max-width: 720px) {
  #tplView .tl-list { gap: 10px; }
  #tplView .tl-row { min-height: 60px; font-size: 18px; padding: 14px 14px 14px 18px; border-radius: 12px; }
  #tplView .tl-chev { font-size: 22px; }
  #tplView .tl-ic { font-size: 22px; }
  #tplDetail .td-wrap { gap: 16px; }
  #tplDetail .td-back { font-size: 17px; min-height: 44px; }
  #tplDetail .td-back .ic { font-size: 24px; }
  #tplDetail .td-title { font-size: 26px; }
  #tplDetail .td-next { font-size: 16px; }
  #tplDetail .td-next small { font-size: 14px; }
  #tplDetail .td-stat { padding: 14px 16px; }
  #tplDetail .td-stat .st-ic { font-size: 26px; width: 28px; }
  #tplDetail .td-stat .st-val { font-size: 26px; }
  #tplDetail .td-stat .st-val small { font-size: 16px; }
  #tplDetail .td-stat .st-sub { font-size: 14px; padding-left: 36px; }
  #tplDetail .td-primary { min-height: 54px; font-size: 18px; }
  #tplDetail .td-sec { padding: 14px 16px; }
  #tplDetail .td-sec h3 { font-size: 17px; }
  #tplDetail .td-list li { font-size: 17px; padding: 10px 2px; }
  #tplDetail .td-list li.d1, #tplDetail .td-list li.d2 { font-size: 16px; }
  #tplDetail .td-edit { min-height: 50px; font-size: 17px; }
  #tplDetail .tc-more { width: 46px; height: 46px; font-size: 22px; }
}

/* =========================================================
 * ログイン画面（Supabase 版）・アカウント
 * ======================================================= */
#authView {
  position: fixed; inset: 0; z-index: 300; overflow: auto; background: var(--bg);
  display: flex; align-items: flex-start; justify-content: center;
  padding: max(48px, env(safe-area-inset-top)) 16px 32px;
}
body.auth-open .topbar, body.auth-open main { visibility: hidden; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.auth-logo { width: 64px; height: 64px; border-radius: 16px; box-shadow: 0 6px 18px rgba(61, 109, 242, .3); }
.auth-brand { font-size: 14px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.auth-card h1 { margin: 2px 0 14px; font-size: 24px; }
#authForm { width: 100%; display: flex; flex-direction: column; gap: 12px; padding: 20px; background: var(--panel); border-radius: 16px; box-shadow: 0 2px 10px rgba(15, 23, 42, .08); }
#authForm .fld { margin: 0; }
#authForm input { width: 100%; font-size: 16px; padding: 11px 12px; border-radius: 10px; }
#authSubmit { min-height: 48px; font-size: 16px; border-radius: 12px; margin-top: 4px; }
#authSubmit:disabled { opacity: .6; }
.auth-msg { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; background: var(--accent-soft); color: var(--text); line-height: 1.5; }
.auth-msg.error { background: color-mix(in srgb, var(--danger) 14%, var(--panel)); color: var(--danger); }
.auth-alt { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 14px; }
.auth-link { border: none; background: none; color: var(--accent); font-size: 15px; padding: 8px 10px; min-height: 40px; }
.auth-link:hover { background: none; text-decoration: underline; }

.acct-head { margin-top: 36px; }
.acct-card { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; background: var(--panel); border-radius: 12px; box-shadow: 0 1px 3px rgba(15, 23, 42, .07); }
.acct-user { display: flex; align-items: center; gap: 8px; font-size: 15px; overflow-wrap: anywhere; }
.acct-user .ic { color: var(--muted); }
.acct-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.acct-acts button { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px; border-radius: 10px; }
.acct-acts .acct-logout { margin-left: auto; color: var(--muted); }
@media (max-width: 720px) {
  #tplView .acct-card { padding: 16px; }
  #tplView .acct-user { font-size: 16px; }
  #tplView .acct-acts button { min-height: 46px; font-size: 16px; }
}
