:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --line: #e2e0da;
  --text: #1c1b18;
  --muted: #6b6960;
  --accent: #1f4e79;
  --p0: #b42318;
  --p0-bg: #fdecea;
  --p1: #b54708;
  --p1-bg: #fff4e6;
  --p2: #8a6d00;
  --p2-bg: #fff9db;
  --p3: #5c5a52;
  --p3-bg: #efeee9;
  --ok: #1b7f4b;
  --warn: #b54708;
  --err: #b42318;
  --gate: #7a1e9c;
  --gate-bg: #f6ecfb;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a;
    --surface: #1e2026;
    --surface-2: #262930;
    --line: #33363e;
    --text: #ecebe6;
    --muted: #a19f97;
    --accent: #8ab4f8;
    --p0: #ff8a80;
    --p0-bg: #3a1f1f;
    --p1: #ffb86b;
    --p1-bg: #3a2a1a;
    --p2: #ffe08a;
    --p2-bg: #3a331a;
    --p3: #b8b6ae;
    --p3-bg: #2c2d31;
    --ok: #5bd48a;
    --warn: #ffb86b;
    --err: #ff8a80;
    --gate: #d9a3f0;
    --gate-bg: #30213a;
  }
}
:root[data-theme="dark"] {
  --bg: #15161a; --surface: #1e2026; --surface-2: #262930; --line: #33363e; --text: #ecebe6; --muted: #a19f97;
  --accent: #8ab4f8; --p0: #ff8a80; --p0-bg: #3a1f1f; --p1: #ffb86b; --p1-bg: #3a2a1a; --p2: #ffe08a; --p2-bg: #3a331a;
  --p3: #b8b6ae; --p3-bg: #2c2d31; --ok: #5bd48a; --warn: #ffb86b; --err: #ff8a80; --gate: #d9a3f0; --gate-bg: #30213a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 6px; }
.brand-mark { font-weight: 700; letter-spacing: 0.02em; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 13px; }
.top-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.today { color: var(--muted); font-variant-numeric: tabular-nums; }
.sources { display: flex; gap: 6px; flex-wrap: wrap; }
.src { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; color: var(--muted); background: var(--surface-2); }
.src::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.src.ok::before { background: var(--ok); }
.src.error::before { background: var(--err); }
.src.unconfigured { opacity: 0.6; }
.btn { font: inherit; padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn[disabled] { opacity: 0.5; cursor: progress; }

.tabs { max-width: 1240px; margin: 0 auto; padding: 10px 16px 0; display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab { font: inherit; font-size: 13px; padding: 7px 14px; border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--text); background: var(--surface); border-color: var(--line); font-weight: 700; }

.app { max-width: 1240px; margin: 0 auto; padding: 16px; }
.loading, .empty { color: var(--muted); padding: 24px 0; text-align: center; }
.error-box { border: 1px solid var(--err); background: var(--p0-bg); color: var(--p0); padding: 12px; border-radius: var(--radius); }
.note-box { border: 1px solid var(--gate); background: var(--gate-bg); color: var(--gate); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.viewas { font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); max-width: 260px; }

.section { margin-bottom: 20px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 10px; margin: 0 0 8px; flex-wrap: wrap; }
.card .section-head { flex-direction: column; align-items: flex-start; gap: 2px; margin-bottom: 6px; }
.section-title { font-size: 15px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
.count { color: var(--muted); font-weight: 500; font-size: 13px; }
.section-hint { color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card .section-head { padding: 10px 14px 0; }
.list { list-style: none; margin: 0; padding: 0; }
.item { padding: 10px 14px; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: start; }
.item:first-child { border-top: 0; }
.item.judgment { padding: 12px 14px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 6px; line-height: 1.6; white-space: nowrap; }
.badge.P0 { color: var(--p0); background: var(--p0-bg); }
.badge.P1 { color: var(--p1); background: var(--p1-bg); }
.badge.P2 { color: var(--p2); background: var(--p2-bg); }
.badge.P3, .badge.none { color: var(--p3); background: var(--p3-bg); }
.badge.gate { color: var(--gate); background: var(--gate-bg); }
.badge.draft { color: var(--p3); background: var(--p3-bg); }
.badge.ext { color: var(--p1); background: var(--p1-bg); }
.badge.conflict { color: var(--p0); background: var(--p0-bg); }
.title { font-weight: 600; }
.title a { color: var(--text); }
.meta { grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); font-size: 12px; }
.due { font-variant-numeric: tabular-nums; }
.due.overdue { color: var(--err); font-weight: 700; }
.due.today { color: var(--warn); font-weight: 700; }
.due.soon { color: var(--warn); }
.next { grid-column: 2; color: var(--text); font-size: 13px; margin-top: 2px; }
.next.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.next-toggle { grid-column: 2; font-size: 12px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }

.actions { grid-column: 2; margin-top: 4px; }
.check { font: inherit; font-size: 12px; padding: 3px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; }
.check:hover { border-color: var(--ok); color: var(--ok); }
.check.is-done { color: var(--muted); }
.check[disabled] { opacity: 0.5; cursor: progress; }
.item.done .title a { color: var(--muted); text-decoration: line-through; }
.badge.done { color: var(--ok); background: var(--p3-bg); font-weight: 600; }
.done-wrap { border-left: 4px solid var(--ok); }
.mine-wrap { border-left-color: var(--accent); }
.kanban { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
@media (min-width: 1100px) { .kanban { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

details.more { border-top: 1px solid var(--line); }
details.more summary { cursor: pointer; padding: 8px 14px; color: var(--muted); font-size: 13px; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "▸ "; }
details.more[open] summary::before { content: "▾ "; }

.judgment-wrap { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--gate); border-radius: var(--radius); overflow: hidden; }
.judgment-wrap .section-head { padding: 12px 14px 4px; }

.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-width: 110px; }
.stat b { display: block; font-size: 20px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12px; }

.event-time { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); font-size: 12px; }
.daysep { padding: 6px 14px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; border-top: 1px solid var(--line); }

.foot { max-width: 1240px; margin: 0 auto; padding: 8px 16px 24px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }

@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  .app { padding: 12px; }
  .item { grid-template-columns: 1fr; }
  .meta, .next, .next-toggle, .actions { grid-column: 1; }
  .section-head { flex-direction: column; align-items: flex-start; gap: 2px; }
  .kanban { grid-template-columns: 1fr; }
  .stat { min-width: calc(50% - 4px); }
}
