:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --column: #e9ebf3;
  --text: #1c1f2b;
  --muted: #667085;
  --border: #d5d9e6;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --danger: #c62828;
  --high: #c62828;
  --high-bg: #fdeaea;
  --low: #52607a;
  --low-bg: #e8ebf2;
  --claude: #8a4b00;
  --claude-bg: #fdf0dc;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1e212d;
    --column: #181b25;
    --text: #e8eaf2;
    --muted: #98a2b8;
    --border: #2d3244;
    --accent: #7c75ff;
    --accent-text: #0e0f18;
    --danger: #ff7b7b;
    --high: #ff8c8c;
    --high-bg: #3a1f23;
    --low: #a9b4cc;
    --low-bg: #272c3b;
    --claude: #ffc97a;
    --claude-bg: #3a2c14;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
}
.topbar h1 { margin: 0; font-size: 20px; flex: 0 0 auto; }
.sync { flex: 1; color: var(--muted); font-size: 13px; }
.who { color: var(--muted); font-size: 13px; }
@media (max-width: 800px) { .who { display: none; } }

.btn {
  font: inherit;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 4px 20px 24px;
  align-items: start;
}

.column {
  background: var(--column);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
}
.column.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.column-head { display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.column-head h2 { margin: 0; font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase; }
.count { background: var(--surface); border-radius: 999px; padding: 0 8px; font-size: 12px; color: var(--muted); }

.cards { display: flex; flex-direction: column; gap: 8px; min-height: 48px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  cursor: grab;
}
.card.p-high { border-left-color: var(--high); }
.card.p-medium { border-left-color: var(--accent); }
.card.dragging { opacity: 0.4; }
.card.is-done .card-title { text-decoration: line-through; color: var(--muted); }

.card-title {
  all: unset;
  display: block;
  width: 100%;
  font-weight: 600;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.card-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.card-notes {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}

.card-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--low-bg); color: var(--low); }
.chip.high { background: var(--high-bg); color: var(--high); }
.chip.overdue { background: var(--high-bg); color: var(--high); font-weight: 600; }
.chip.claude { background: var(--claude-bg); color: var(--claude); }
.spacer { flex: 1; }

.move { display: flex; gap: 2px; }
.move button {
  font: inherit;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.move button:hover { border-color: var(--border); color: var(--text); }

.drop-marker { height: 3px; border-radius: 2px; background: var(--accent); }

.quick-add input {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text);
}
.quick-add input::placeholder { color: var(--muted); }
.quick-add input:focus { border-style: solid; border-color: var(--accent); background: var(--surface); }

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; }
input, textarea, select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
textarea { resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row label { min-width: 120px; }
.actions { display: flex; gap: 8px; align-items: center; }
.meta { margin: 0; font-size: 12px; color: var(--muted); }
.error { margin: 0; color: var(--danger); font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  max-width: calc(100vw - 32px);
}

@media (hover: none) {
  .card { cursor: default; }
}

@media (max-width: 800px) {
  .board {
    grid-template-columns: repeat(3, 85vw);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 16px;
  }
  .column { scroll-snap-align: center; }
  .topbar { padding: 10px 16px; }
  .board { padding-left: 16px; padding-right: 16px; }
}

/* ---------- categories ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 0 20px 12px;
}
.filter {
  font: inherit;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.filter:hover { border-color: var(--accent); }
.filter[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.filter.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; }
.filter .n { opacity: 0.7; font-size: 12px; }
.filter-manage { margin-left: auto; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cat, var(--muted));
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.15);
}
.chip.cat { display: inline-flex; align-items: center; gap: 5px; }

.btn.small { padding: 4px 10px; font-size: 13px; }

.cat-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.cat-row { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.cat-row .cat-name { flex: 1; min-width: 0; }
.cat-row input[type="color"] { width: 38px; height: 34px; padding: 2px; flex: 0 0 auto; cursor: pointer; }
.cat-row .meta { white-space: nowrap; }
.cat-add { margin-bottom: 8px; }

@media (max-width: 800px) {
  .filters { padding-left: 16px; padding-right: 16px; }
}

.chip.focus { background: var(--claude-bg); color: var(--claude); }
.chip.focus.past { background: var(--low-bg); color: var(--low); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
label.check input { width: 16px; height: 16px; padding: 0; }

/* ---------- images ---------- */
.card-cover {
  all: unset;
  position: relative;
  display: block;
  width: calc(100% + 24px);
  margin: -10px -12px 8px;
  height: 130px;
  overflow: hidden;
  border-radius: 9px 9px 0 0;
  background: var(--column);
  cursor: zoom-in;
}
.card-cover:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgb(0 0 0 / 0.65);
  color: #fff;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
}
.card.file-over { outline: 2px dashed var(--accent); outline-offset: 2px; }

.images-section { display: flex; flex-direction: column; gap: 8px; border: 1px dashed var(--border); border-radius: 10px; padding: 10px; }
.images-section.file-over { border-color: var(--accent); background: var(--column); }
.images-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.image-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.image-grid:empty { display: none; }
.image-item { position: relative; width: 84px; height: 84px; }
.image-item .open { all: unset; display: block; width: 100%; height: 100%; cursor: zoom-in; border-radius: 8px; overflow: hidden; background: var(--column); }
.image-item .open:focus-visible { outline: 2px solid var(--accent); }
.image-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-item .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--danger);
  cursor: pointer;
}
.file-btn { align-self: flex-start; flex-direction: row; cursor: pointer; color: var(--text); font-size: 13px; }

dialog.lightbox { width: auto; max-width: 96vw; background: #111; border-color: #333; color: #eee; padding: 10px; }
dialog.lightbox::backdrop { background: rgb(0 0 0 / 0.8); }
.lightbox img { display: block; max-width: min(92vw, 1600px); max-height: 78vh; margin: 0 auto; border-radius: 6px; background: #222; }
.lb-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.lb-bar .btn { background: #222; color: #eee; border-color: #444; }
.lb-caption { flex: 1; text-align: center; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
