:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --column: #eef0f5;
  --text: #1b1f2a;
  --muted: #5d6578;
  --border: #e3e6ef;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #b42318;
  --todo: #475467;
  --doing: #b54708;
  --done: #067647;
  --live: #067647;  --live-bg: #e5f6ec;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --column: #141720;
    --text: #e8eaf0;
    --muted: #9aa2b5;
    --border: #2a2f3c;
    --accent: #8b85ff;
    --accent-soft: #23234a;
    --danger: #fda29b;
    --todo: #c0c6d4;
    --doing: #fdb022;
    --done: #75e0a7;
    --live: #75e0a7;  --live-bg: #123020;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top, main, .foot { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 24px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--accent); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { margin: 8px 0 4px; font-size: 28px; letter-spacing: -0.02em; }
.lede { margin: 0 0 20px; color: var(--muted); }

.account { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; }
.who { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.live {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  color: var(--muted); background: var(--column);
}
.live.on { color: var(--live); background: var(--live-bg); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--border); background: var(--surface);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, select:focus-visible, .kcard-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.ghost { padding: 4px 10px; font-size: 14px; white-space: nowrap; }
.danger-text { color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }

.message { margin: 0; min-height: 1.5em; color: var(--muted); font-size: 14px; }
.fine { margin: 0; color: var(--muted); font-size: 13px; }

/* Sign in */
.auth { max-width: 420px; margin: 8px auto 0; padding: 20px; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button { flex: 1; border-radius: 999px; font-size: 14px; }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.auth-form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; font-size: 14px; }
.field > span { color: var(--muted); }

/* Board bar */
.boardbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.boardbar select { flex: 1 1 200px; width: auto; min-width: 0; }

/* Columns */
.columns {
  display: grid; gap: 14px; margin-top: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.column {
  background: var(--column); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 180px;
}
.column.drop-target { border-color: var(--accent); background: var(--accent-soft); }
.column h2 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.column[data-status="todo"] h2 { color: var(--todo); }
.column[data-status="doing"] h2 { color: var(--doing); }
.column[data-status="done"] h2 { color: var(--done); }
.count {
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-variant-numeric: tabular-nums;
}

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; flex: 1; align-content: start; }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 10px 6px; cursor: grab;
}
.kcard.dragging { opacity: 0.4; }
.kcard-open {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 0;
  border-radius: 6px; cursor: pointer;
}
.kcard-title { display: block; font-weight: 600; overflow-wrap: anywhere; white-space: pre-wrap; }
.kcard-notes {
  display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  margin-top: 2px; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap;
}
.kcard-actions { display: flex; gap: 4px; margin-top: 6px; justify-content: flex-end; }
.icon { padding: 0; width: 32px; height: 32px; line-height: 1; font-size: 15px; color: var(--muted); background: transparent; }
.icon[data-action="delete"] { margin-left: auto; }
.icon[data-action="delete"]:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }

.add-card { display: flex; gap: 6px; }
.add-card input { flex: 1; min-width: 0; background: var(--surface); }

/* Editor */
dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(10, 12, 20, 0.5); }
.editor { display: grid; gap: 12px; padding: 20px; }
.editor h2 { margin: 0; font-size: 18px; }
.editor-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.foot { padding-top: 32px; padding-bottom: 32px; color: var(--muted); font-size: 13px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

@media (max-width: 760px) {
  .columns { grid-template-columns: 1fr; }
  .column { min-height: 0; }
  .icon { width: 40px; height: 40px; }
}
