:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #dfe3ea;
  --accent: #2563eb;
  --recurring: #d97706;
  --done: #16a34a;
  --danger: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --panel: #1c1f26;
    --text: #e6e8ee;
    --muted: #8b93a3;
    --border: #2d323d;
    --accent: #60a5fa;
    --recurring: #fbbf24;
    --done: #4ade80;
    --danger: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body { display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 0; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar button {
  padding: 6px 14px; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font: inherit; cursor: pointer;
}
.topbar button:hover { border-color: var(--accent); }
.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 800px) {
  body { display: block; height: auto; }
  .board { grid-template-columns: 1fr; }
}

dialog {
  width: min(900px, 94vw); max-height: 80vh; padding: 0;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog[open] { display: flex; flex-direction: column; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-body { overflow: auto; padding: 0 16px 12px; }
#history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#history-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 8px 8px 0; position: sticky; top: 0; background: var(--panel); }
#history-table td { padding: 6px 8px 6px 0; border-top: 1px solid var(--border); vertical-align: top; }
#history-table td { white-space: pre-wrap; word-break: break-word; }
#history-table .when { white-space: nowrap; color: var(--muted); }
#history-table .detail { color: var(--muted); }
.col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
}
.col h2 { margin: 0 0 10px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
#col-recurring h2 { color: var(--recurring); }
#col-done h2 { color: var(--done); }
.count { font-size: 12px; color: var(--muted); font-weight: 400; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 40px; }
.empty { color: var(--muted); font-style: italic; padding: 8px 4px; }

.item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#col-recurring .item { border-left: 3px solid var(--recurring); }
#col-done .item { border-left: 3px solid var(--done); }
.item[draggable="true"] { cursor: grab; }
.item.dragging { opacity: 0.4; }
.item.drop-before { box-shadow: 0 -3px 0 0 var(--accent); }
.item.drop-after { box-shadow: 0 3px 0 0 var(--accent); }

.title { flex: 1; word-break: break-word; white-space: pre-wrap; }
.title[contenteditable="true"],
.title[contenteditable="plaintext-only"] { outline: 2px solid var(--accent); border-radius: 3px; padding: 0 3px; }
.stamp { display: block; font-size: 12px; color: var(--muted); }

.check {
  width: 20px; height: 20px; flex: none;
  border: 2px solid var(--muted); border-radius: 50%;
  background: transparent; cursor: pointer; padding: 0;
}
.check:hover { border-color: var(--done); background: color-mix(in srgb, var(--done) 25%, transparent); }
.icon {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 15px; padding: 2px 4px; border-radius: 4px;
}
.icon:hover { color: var(--text); }
.icon.del:hover { color: var(--danger); }

.add { display: flex; gap: 6px; margin-top: 8px; }
.add textarea {
  flex: 1; min-width: 0; padding: 8px 10px; resize: none; overflow-y: auto; max-height: 200px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.add textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.add button {
  padding: 8px 14px; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; font: inherit; cursor: pointer;
}
