:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel2: #f0f3f8;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --shadow: 0 6px 24px rgba(15, 23, 42, .12);
  --radius: 14px;
  --side-w: 250px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --topbar-h: calc(61px + var(--sat));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a; --panel: #1e293b; --panel2: #263449; --text: #e5e7eb; --muted: #94a3b8;
    --line: #334155; --accent: #60a5fa; --accent-soft: #1e3a5f; --danger: #f87171; --warn: #fbbf24; --ok: #4ade80;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.spacer { flex: 1; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

/* ---- ログイン */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { background: var(--panel); border-radius: 20px; box-shadow: var(--shadow); padding: 32px 24px; width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: #fff; font-size: 36px; display: grid; place-items: center; margin: 0 auto 12px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card input { width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel2); font-size: 18px; text-align: center; letter-spacing: .1em; margin: 16px 0 12px; }
.login-card .btn { width: 100%; }

/* ---- ボタン類 */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 16px; font-size: 15px; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.round { width: 48px; height: 48px; border-radius: 50%; padding: 0; font-size: 26px; line-height: 1; flex: none; }
.icon-btn { border: 0; background: transparent; width: 44px; height: 44px; border-radius: 10px; font-size: 20px; }
.icon-btn:active { background: var(--panel2); }
.mini-btn { border: 0; background: transparent; color: var(--muted); font-size: 16px; padding: 2px 8px; border-radius: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel2); border-radius: 999px; padding: 6px 12px; font-size: 13px; }

/* ---- レイアウト */
#app { display: grid; grid-template-columns: var(--side-w) 1fr; grid-template-rows: auto 1fr; min-height: 100vh; min-height: 100dvh; }
.topbar { grid-column: 1 / -1; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--sat)) 12px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 20px; white-space: nowrap; }
.count { color: var(--muted); font-size: 14px; }
#search { width: 160px; max-width: 40vw; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel2); font-size: 14px; }
#menuBtn { display: none; }
#side { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 10px calc(12px + var(--sab)); display: flex; flex-direction: column; gap: 14px; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); overflow-y: auto; }
.side-section { display: flex; flex-direction: column; gap: 2px; }
.side-bottom { margin-top: auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .05em; padding: 4px 10px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; text-align: left; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
.nav-item:hover { background: var(--panel2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-ico { width: 20px; text-align: center; }
.nav-n { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 400; }
.nav-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin: 0 5px; }
#main { padding: 14px 16px 120px; max-width: 900px; width: 100%; }

/* ---- セクションとタスク */
.sec { margin-bottom: 18px; }
.sec-h { display: flex; align-items: baseline; gap: 8px; margin: 6px 4px 8px; font-size: 14px; font-weight: 700; color: var(--muted); }
.sec-h.over { color: var(--danger); }
.sec-h.today { color: var(--accent); }
.sec-h .n { font-weight: 400; }
.tasks { background: var(--panel); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.05); overflow: hidden; }
.task { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.task:last-child { border-bottom: 0; }
.task:hover { background: var(--panel2); }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.check { flex: none; width: 24px; height: 24px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; display: grid; place-items: center; color: #fff; font-size: 14px; padding: 0; }
.check.on { background: var(--ok); border-color: var(--ok); }
.check.big { width: 30px; height: 30px; font-size: 17px; }
.check.p3 { border-color: var(--danger); }
.check.p2 { border-color: var(--warn); }
.t-body { flex: 1; min-width: 0; }
.t-title { font-size: 16px; overflow-wrap: anywhere; }
.t-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.t-meta .due { font-weight: 600; }
.t-meta .due.over { color: var(--danger); }
.t-meta .due.today { color: var(--accent); }
.t-meta .due.soon { color: var(--warn); }
.t-meta .list { display: inline-flex; align-items: center; gap: 4px; }
.t-meta .list i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.t-meta .wait { color: var(--warn); }
.t-meta .pri { color: var(--danger); font-weight: 700; }
.t-note { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--muted); padding: 48px 12px; }
.empty .big { font-size: 40px; }

/* ---- 追加バー */
.quick { position: fixed; left: var(--side-w); right: 0; bottom: 0; z-index: 15; display: flex; gap: 8px; align-items: center; padding: 10px 16px calc(10px + var(--sab)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.quick input { flex: 1; padding: 13px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); font-size: 16px; }
.quick-hint { position: fixed; left: calc(var(--side-w) + 16px); right: 80px; bottom: calc(72px + var(--sab)); z-index: 15; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; color: var(--muted); box-shadow: var(--shadow); }
.quick-hint b { color: var(--text); }

/* ---- シート(詳細・設定) */
.modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet { position: fixed; z-index: 50; background: var(--panel); box-shadow: var(--shadow); left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border-radius: 18px; overflow: auto; }
.sheet-grip { display: none; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
.sheet-body { padding: 18px 18px calc(18px + var(--sab)); display: flex; flex-direction: column; gap: 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.row { display: flex; gap: 10px; align-items: center; }
.row .token { flex: 1; overflow-wrap: anywhere; background: var(--panel2); padding: 8px; border-radius: 8px; }
#dTitle { flex: 1; font-size: 18px; font-weight: 600; border: 0; background: transparent; resize: none; padding: 4px 0; outline: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label input, label select, label textarea, .stack input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); font-size: 15px; color: var(--text); width: 100%; }
label textarea { resize: vertical; min-height: 90px; }
.sheet-quick { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
details { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.lm-row { display: flex; gap: 8px; align-items: center; }
.lm-row input[type=text] { flex: 1; }
.lm-row input[type=color] { width: 36px; height: 36px; padding: 0; border: 0; background: transparent; }

/* ---- トースト */
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--sab)); transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }
.toast button { background: transparent; border: 0; color: #93c5fd; margin-left: 10px; font-weight: 600; }

/* ---- スマホ */
@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  #menuBtn { display: inline-block; }
  #side { position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 82vw); height: auto; z-index: 35; transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); padding-top: calc(16px + var(--sat)); }
  #side.open { transform: none; }
  #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  #main { padding: 12px 12px 130px; }
  .quick, .quick-hint { left: 0; }
  .quick-hint { left: 16px; }
  #search { width: 110px; }
  .sheet { left: 0; right: 0; top: auto; bottom: 0; transform: none; width: auto; max-height: calc(100vh - 40px); border-radius: 18px 18px 0 0; }
  .sheet-grip { display: block; }
  .grid2 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }
