:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1d4ed8;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d23;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2a2f37;
    --primary: #60a5fa;
    --primary-soft: #1e293b;
    --danger: #f87171;
    --danger-soft: #3b1515;
    --warn: #fbbf24;
    --warn-soft: #3a2a0a;
    --ok: #4ade80;
    --ok-soft: #12301d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
  font-size: 16px; /* iPhoneで勝手にズームしないように */
}
label { display: block; margin: 12px 0; font-size: 14px; color: var(--muted); }
label input, label select, label textarea { margin-top: 6px; }

.primary {
  background: var(--primary); color: #fff; border: 0; border-radius: 10px;
  padding: 12px 16px; width: 100%; font-weight: 600;
}
.secondary {
  background: var(--primary-soft); color: var(--primary); border: 0; border-radius: 10px;
  padding: 10px 14px; font-weight: 600;
}
.danger-btn {
  background: transparent; color: var(--danger); border: 1px solid var(--danger);
  border-radius: 10px; padding: 10px 14px; width: 100%;
}
.link { background: none; border: 0; color: var(--primary); padding: 8px 0; }
.msg { min-height: 1.5em; font-size: 14px; }
.msg.error { color: var(--danger); }

/* ログイン */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  background: var(--card); border-radius: 16px; padding: 24px; width: 100%; max-width: 380px;
  box-shadow: 0 2px 12px rgb(0 0 0 / .06);
}
.auth-card h1 { margin: 0 0 4px; font-size: 24px; }

/* 上部バー */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
}
.topbar h1 { font-size: 22px; margin: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--card); font-size: 20px;
}
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main {
  padding: 0 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 720px; margin: 0 auto;
}
#alert-area { max-width: 720px; margin: 0 auto; padding: 0 16px; }

/* 下のタブ */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button {
  background: none; border: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted);
}
.tabbar button span { font-size: 20px; }
.tabbar button.active { color: var(--primary); font-weight: 600; }

/* カード・一覧 */
.card {
  background: var(--card); border-radius: 14px; padding: 14px; margin: 10px 0;
}
.section-title { font-size: 13px; color: var(--muted); margin: 18px 4px 6px; font-weight: 600; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.task {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin: 8px 0;
}
.task.done { opacity: .55; }
.task.done .task-title { text-decoration: line-through; }
.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent; margin-top: 2px;
  display: grid; place-items: center; font-size: 15px; color: #fff;
}
.check.on { background: var(--ok); border-color: var(--ok); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; line-height: 1.35; word-break: break-word; }
.task-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.task-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.new { background: var(--danger); color: #fff; }
.badge.gray { background: var(--line); color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.alert {
  border-radius: 12px; padding: 12px 14px; margin: 6px 0; font-size: 14px;
  background: var(--danger-soft); color: var(--danger); font-weight: 600;
}
.alert.info { background: var(--primary-soft); color: var(--primary); }

/* カレンダー */
.cal-head { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; }
.cal-head h2 { font-size: 18px; margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1 / 1.1; background: var(--card); border-radius: 10px; border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; padding-top: 6px; font-size: 14px;
}
.cal-day.other { opacity: .35; }
.cal-day.today { border-color: var(--primary); }
.cal-day.selected { background: var(--primary); color: #fff; }
.cal-dots { display: flex; gap: 2px; margin-top: 4px; flex-wrap: wrap; justify-content: center; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--danger); }
.dot.done { background: var(--ok); }

/* 時間割 */
.tt-wrap { overflow-x: auto; }
.tt { display: grid; grid-template-columns: 20px repeat(6, minmax(0, 1fr)); gap: 3px; }
.tt-h { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.tt-p { display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.tt-cell {
  min-height: 64px; background: var(--card); border: 0; border-radius: 8px; padding: 4px 2px;
  font-size: 11px; line-height: 1.25; text-align: center; word-break: break-all;
}
.tt-cell.filled { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tt-cell.today { outline: 2px solid var(--primary); }
.today-class { display: flex; align-items: center; gap: 12px; }
.today-class .when { font-size: 13px; color: var(--muted); width: 74px; flex: none; }
.today-class .name { flex: 1; font-weight: 600; }
.att-btn {
  border: 0; border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 600;
  background: var(--danger-soft); color: var(--danger); white-space: nowrap;
}
.att-btn.on { background: var(--ok-soft); color: var(--ok); }
.att-btn.later { background: var(--line); color: var(--muted); }

/* 編集ダイアログ */
dialog {
  border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 380px);
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.switch-row { display: flex; align-items: center; justify-content: space-between; margin: 12px 0; }
.switch-row input { width: auto; transform: scale(1.3); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 50; max-width: 90vw; text-align: center;
}
ol.howto { padding-left: 20px; line-height: 1.7; font-size: 14px; }
code { background: var(--line); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
