:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --border: #e1e5ef;
  --text: #1c2233;
  --muted: #6b7489;
  --accent: #4f6bed;
  --accent-soft: rgba(79, 107, 237, 0.12);
  --done: #2fb67c;
  --danger: #e5484d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.05), 0 4px 16px rgba(20, 30, 60, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #181c25;
    --surface-2: #222734;
    --border: #2b3140;
    --text: #e9ecf3;
    --muted: #8d95a8;
    --accent: #7b93ff;
    --accent-soft: rgba(123, 147, 255, 0.16);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI Variable", "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { border-radius: 8px; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync-dot.ok { background: var(--done); }
.sync-dot.busy { background: var(--accent); animation: pulse 1s infinite; }
.sync-dot.err { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.banner {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.banner code { background: var(--surface); padding: 1px 6px; border-radius: 6px; }

/* ---------- レイアウト ---------- */
.layout { max-width: 1100px; margin: 0 auto; display: flex; gap: 24px; padding: 16px; }
main { flex: 1; min-width: 0; padding-bottom: 90px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border: none;
  background: none;
  border-radius: 12px;
  font-size: 11px;
  color: var(--muted);
}
.tabbar .ico { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: 0.7; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar button.active .ico { filter: none; opacity: 1; }

@media (min-width: 860px) {
  .tabbar {
    position: sticky;
    top: 76px;
    flex-direction: column;
    justify-content: flex-start;
    align-self: flex-start;
    width: 190px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .tabbar button { flex-direction: row; gap: 10px; padding: 10px 12px; font-size: 14px; }
  .tabbar button.active { background: var(--accent-soft); }
  main { padding-bottom: 24px; }
}

.view { display: none; }
.view.active { display: block; animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.grid { display: grid; gap: 16px; }
@media (min-width: 1000px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid .card:first-child { grid-row: span 2; }
}

/* ---------- カード ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.grid .card { margin-bottom: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
h1 { margin: 0; font-size: 24px; }
h2 { margin: 0; font-size: 16px; }

.hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 4px 4px 20px; }
.hero-date { margin: 0; color: var(--muted); font-size: 14px; }
.ring {
  --p: 0;
  width: 68px; height: 68px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--done) calc(var(--p) * 1%), var(--surface-2) 0);
  font-weight: 700;
  font-size: 14px;
}
.ring span { width: 54px; height: 54px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; }

/* ---------- リスト ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: none; }
.list .main { flex: 1; min-width: 0; }
.list .title { overflow-wrap: anywhere; }
.list .sub { font-size: 12px; color: var(--muted); }
.list .sub.overdue { color: var(--danger); }
.list li.done .title { text-decoration: line-through; color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 12px 4px; }
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); min-width: 44px; }

.check {
  appearance: none;
  width: 24px; height: 24px;
  flex-shrink: 0;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: 0.15s;
}
.check:checked { background: var(--done); border-color: var(--done); }
.check:checked::after { content: "✓"; color: #fff; font-size: 14px; font-weight: 700; }

.streak { font-size: 12px; color: var(--muted); white-space: nowrap; }
.dots { display: flex; gap: 3px; margin-top: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 2px; background: var(--surface-2); }
.dots i.on { background: var(--done); }
.dots i.off { opacity: 0.35; }

.icon-btn {
  border: none;
  background: none;
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.day-group { margin-top: 12px; }
.day-group h3 { margin: 0 0 2px; font-size: 13px; color: var(--muted); font-weight: 600; }
.ev-bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--accent); flex-shrink: 0; }

/* ---------- フォーム ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn:disabled { opacity: 0.5; cursor: default; }
.link { border: none; background: none; color: var(--accent); font-size: 13px; padding: 4px; }

input, select {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.inline-form { display: flex; gap: 8px; margin: 8px 0; }
.inline-form input[name="title"], .inline-form input[name="summary"] { flex: 1; }
.inline-form.wrap { flex-wrap: wrap; }
.inline-form.wrap input[name="summary"] { flex-basis: 100%; }
.hint { margin: 0 0 4px; font-size: 12px; color: var(--muted); }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 12px; color: var(--muted); }

dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(10, 14, 25, 0.45); }
dialog h2 { margin-bottom: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
dialog label input { color: var(--text); font-size: 15px; }
dialog .toggle { flex-direction: row; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.days { border: none; padding: 0; margin: 0 0 4px; }
.days legend { font-size: 13px; color: var(--muted); margin-bottom: 4px; padding: 0; }
#day-picker { display: flex; gap: 6px; }
#day-picker label { margin: 0; }
#day-picker input { position: absolute; opacity: 0; pointer-events: none; }
#day-picker span {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
#day-picker input:checked + span { background: var(--accent); color: #fff; font-weight: 600; }
#day-picker input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: calc(100vw - 32px);
}
@media (min-width: 860px) { .toast { bottom: 24px; } }
