/* ---------- フォント（同梱・SIL OFL） ---------- */
@font-face { font-family: "TM Grotesk"; src: url("fonts/space-grotesk.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "TM Kaku"; src: url("fonts/zen-kaku-gothic-new-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "TM Kaku"; src: url("fonts/zen-kaku-gothic-new-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --text: #14211f;
  --muted: #5b6b68;
  --border: #dbe5e2;
  --accent: #0f766e;
  --accent-soft: #d9f0ec;
  --accent-text: #ffffff;
  --danger: #b42318;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --shadow: 0 1px 2px rgba(15, 40, 36, .06), 0 4px 14px rgba(15, 40, 36, .05);
  --radius: 14px;
  --addbar-h: 74px;
  --font-body: "TM Grotesk", system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-ui: "TM Grotesk", "TM Kaku", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --grad: linear-gradient(135deg, #14b8a6, #0f766e);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514;
    --surface: #17211f;
    --text: #e8f1ef;
    --muted: #98aaa6;
    --border: #2a3a37;
    --accent: #2dd4bf;
    --accent-soft: #123a35;
    --accent-text: #05211d;
    --danger: #ff8a7a;
    --warn-bg: #3a2f10;
    --warn-text: #ffe29a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  background-image: radial-gradient(900px 380px at 85% -120px, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%);
  background-repeat: no-repeat;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button, .pagenav a, .chip, .lbl, .sync-badge, .count, .group-title, .panel-title, dialog h2, .meta, .notice-row { font-family: var(--font-ui); }
.meta, .group-title, .count, .nav-count { font-variant-numeric: tabular-nums; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- ボタン共通 ---------- */
.primary, .ghost, .danger {
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  border: 1px solid transparent;
  font-weight: 600;
}
.primary { background: var(--accent); color: var(--accent-text); }
.primary:disabled { opacity: .6; cursor: default; }
.ghost { background: transparent; border-color: var(--border); }
.ghost.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.wide { width: 100%; }

/* ---------- ログイン ---------- */
#auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 14px; }
.auth-lead { text-align: center; }
.auth-lead { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.auth-card label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
.auth-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  font-size: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}
.auth-actions { display: flex; gap: 10px; margin-top: 18px; }
.auth-actions .primary { flex: 1; }
.auth-error { margin: 0 0 6px; font-size: 14px; color: var(--danger); }
.auth-error.info { color: var(--accent); }

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  margin: 0;
  font-family: "TM Grotesk", system-ui, sans-serif;
  font-size: 22px; font-weight: 700; letter-spacing: -.02em; line-height: 1;
}
.wordmark b { font-weight: 700; color: var(--accent); }
.auth-brand .wordmark { font-size: 32px; }
.logo { width: 30px; height: 30px; flex: none; filter: drop-shadow(0 2px 5px rgba(15,118,110,.3)); }
.logo-lg { width: 60px; height: 60px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 20px; line-height: 1;
}

.pagenav {
  display: inline-flex;
  gap: 2px;
  margin-top: 10px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.pagenav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 18px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px; font-weight: 600;
  text-decoration: none;
}
.pagenav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
.nav-count { font-size: 12px; font-weight: 700; opacity: .85; }

.sync-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.sync-badge i { width: 8px; height: 8px; border-radius: 50%; background: #9aa9a6; display: inline-block; }
.sync-badge[data-state="ok"] i { background: #22c55e; }
.sync-badge[data-state="busy"] i { background: #f59e0b; }
.sync-badge[data-state="off"] i { background: #ef4444; }
.sync-badge[data-state="demo"] i { background: #60a5fa; }

/* ---------- お知らせ ---------- */
.notice { max-width: 1100px; margin: 12px auto 0; padding: 0 12px; display: grid; gap: 8px; }
.notice-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px;
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 12px;
  font-size: 14px;
}
.notice-row.demo { background: var(--accent-soft); color: var(--text); }

/* ---------- メイン ---------- */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 12px 40px;
}
body[data-route="list"] .main {
  padding-bottom: calc(var(--addbar-h) + env(safe-area-inset-bottom) + 28px);
}

/* 追加ボタン（スマホは画面下に固定） */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.add-btn {
  min-height: 54px;
  padding: 6px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px; font-weight: 700; line-height: 1.25;
}
.add-btn .plus { font-size: 16px; line-height: 1; }
.add-today { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(15,118,110,.28); }
.add-tomorrow { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.lists { display: grid; gap: 24px; }

.panel-title {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 4px 10px;
  font-size: 17px;
}
.count {
  min-width: 24px; padding: 0 8px;
  text-align: center; font-size: 13px; font-weight: 700;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 999px;
}

/* 日付ごとのまとまり */
.group { margin-bottom: 18px; }
.group-title {
  display: flex; align-items: center; gap: 8px;
  margin: 0 4px 6px;
  font-size: 13px; font-weight: 700;
  color: var(--muted);
}
.group-count { font-size: 12px; font-weight: 600; }
.group.today .group-title { color: var(--accent); }
.group.overdue .group-title { color: var(--danger); }
.group.overdue .task { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.task-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 8px;
}
.empty {
  margin: 0;
  display: grid; justify-items: center; gap: 6px;
  padding: 22px 12px; text-align: center;
  color: var(--muted); font-size: 14px;
  border: 1px dashed var(--border); border-radius: var(--radius);
  list-style: none;
}

.task {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.check {
  width: 40px; height: 44px;
  display: grid; place-items: center;
  background: none; border: none; padding: 0;
}
.check-mark {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border: 2px solid var(--muted);
  border-radius: 50%;
  font-size: 14px; font-weight: 800; line-height: 1;
  color: transparent;
  transition: background .12s, border-color .12s, color .12s;
}
.check:hover .check-mark { border-color: var(--accent); }
.check[aria-checked="true"] .check-mark {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}

.body {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  min-width: 0;
  padding: 8px 4px;
  background: none; border: none; text-align: left;
}
.title { word-break: break-word; overflow-wrap: anywhere; }
.note-preview {
  max-width: 100%;
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta { font-size: 11px; color: var(--muted); }

.task.done .title { text-decoration: line-through; color: var(--muted); }

.quick {
  flex: none;
  padding: 6px 10px; min-height: 32px;
  font-size: 12px; font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}
.quick:hover { color: var(--accent); border-color: var(--accent); }

/* 空表示のイラスト */
.ill { width: 96px; height: 72px; opacity: .95; }
.ill-a { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.ill-s { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.ill-f { fill: var(--accent); opacity: .35; }
.ill-f2 { fill: var(--accent); }
.ill-check { stroke-width: 4; }

/* ---------- 完了済みページ ---------- */
.done-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }

/* ---------- ダイアログ ---------- */
dialog {
  width: calc(100% - 32px);
  max-width: 460px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(8, 20, 18, .5); }
#task-form, .menu { padding: 20px; display: grid; gap: 14px; }
dialog h2 { margin: 0; font-size: 18px; }

.field { display: grid; gap: 6px; }
.lbl { font-size: 13px; color: var(--muted); }
#task-form input[type="text"], #task-form input[type="date"], #task-form textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  resize: vertical;
}
.date-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.date-row input[type="date"] { flex: 1 1 150px; width: auto; min-width: 0; }
.chip {
  padding: 8px 14px; min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 13px; font-weight: 600;
}
.chip:hover { color: var(--accent); border-color: var(--accent); }
.meta-line { margin: 0; font-size: 12px; color: var(--muted); }

.dialog-actions { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

.menu-item {
  width: 100%; text-align: left;
  padding: 12px 14px; min-height: 46px;
  background: transparent;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px;
}
.account-line { margin: 0; font-size: 12px; color: var(--muted); word-break: break-all; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  background: #14211f; color: #fff;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
body[data-route="list"] .toast {
  bottom: calc(var(--addbar-h) + env(safe-area-inset-bottom) + 14px);
}

/* ---------- PC ---------- */
@media (min-width: 900px) {
  .topbar { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
  .main { padding: 20px 20px 40px; }
  body[data-route="list"] .main { padding-bottom: 40px; }
  .notice { padding: 0 20px; }

  .addbar {
    position: static;
    display: flex; gap: 10px;
    padding: 0; margin-bottom: 20px;
    background: none; border: none;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .add-btn {
    flex-direction: row; gap: 6px;
    min-height: 46px; padding: 0 20px;
    font-size: 14px;
  }

  .lists {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
    align-items: start;
  }
  #page-done { max-width: 640px; }

  .toast, body[data-route="list"] .toast { bottom: 24px; }
}
