:root {
  --paper: #ffffff;
  --paper-2: #f3f4f6;
  --paper-3: #e5e7eb;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #9ca3af;
  --line: #d1d5db;
  --accent: #111827;
  --accent-ink: #ffffff;
  --danger: #b91c1c;
  --card: #ffffff;
  --shadow: none;
  --radius: 6px;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --col-backlog: #9ca3af;
  --col-todo: #2563eb;
  --col-doing: #d97706;
  --col-done: #16a34a;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1115;
    --paper-2: #181b21;
    --paper-3: #23272f;
    --ink: #e5e7eb;
    --ink-2: #9ca3af;
    --ink-3: #6b7280;
    --line: #2f343d;
    --accent: #e5e7eb;
    --accent-ink: #0f1115;
    --danger: #f87171;
    --card: #1c2027;
    --shadow: none;
    --col-backlog: #6b7280;
    --col-todo: #60a5fa;
    --col-doing: #fbbf24;
    --col-done: #4ade80;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100dvh;
}

.mono { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.01em; }

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

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__mark { display: none; }
.topbar__repo {
  appearance: none; border: 0; background: none; color: var(--ink);
  font: inherit; font-weight: 700; padding: 4px 0; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw;
}
.topbar__actions { display: flex; align-items: center; gap: 6px; }

.search input {
  appearance: none; border: 1px solid var(--line); background: var(--paper-2);
  color: var(--ink); font: inherit; font-size: 14px; border-radius: 6px;
  padding: 6px 12px; width: 140px; transition: width .2s ease;
}
.search input:focus { outline: none; width: 200px; border-color: var(--accent); }
@media (max-width: 480px) { .search input { width: 96px; } .search input:focus { width: 140px; } }

.iconbtn {
  appearance: none; border: 0; background: none; color: var(--ink-2);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  display: inline-grid; place-items: center;
}
.iconbtn:hover { background: var(--paper-2); color: var(--ink); }
.iconbtn.is-spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Status line ---------- */
.statusline {
  font-size: 13px; padding: 6px 16px; color: var(--ink-2);
  background: var(--paper-2); border-bottom: 1px solid var(--line);
}
.statusline[data-kind="error"] { color: var(--danger); }
.statusline[hidden] { display: none; }

/* ---------- Board ---------- */
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(280px, 1fr);
  gap: 12px;
  padding: 14px 16px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 16px;
  min-height: 0;
}
@media (max-width: 720px) {
  .board { grid-auto-columns: 86vw; gap: 10px; }
  .quickadd { grid-template-columns: 1fr auto; }
  .quickadd select, #intake-button { display: none; }
}

.column {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  scroll-snap-align: start;
  transition: background .15s ease, box-shadow .15s ease;
}
.column.is-over { background: var(--paper-3); border-color: var(--ink-2); }

.column__head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 12px 14px 8px;
}
.column__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--col-color); align-self: center; }
.column__name { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; }
.column__count { color: var(--ink-3); font-family: var(--font-mono); font-size: 12px; }
.column__add {
  margin-left: auto; appearance: none; border: 0; background: none; color: var(--ink-3);
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 18px; line-height: 1;
}
.column__add:hover { background: var(--paper-3); color: var(--ink); }

.column__list {
  flex: 1; min-height: 60px; overflow-y: auto;
  padding: 2px 10px 12px; display: flex; flex-direction: column; gap: 8px;
  overscroll-behavior: contain;
}
.column__empty {
  color: var(--ink-3); font-size: 13px; text-align: center; padding: 24px 8px;
  border: 1px dashed var(--line); border-radius: 6px; margin: 2px 0;
}

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px 8px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  transition: opacity .12s ease;
}
.card:hover { border-color: var(--ink-3); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.is-dragging { opacity: 0.35; }
.card.is-pending { opacity: 0.6; }
.card--done .card__title { color: var(--ink-2); text-decoration: line-through; text-decoration-color: var(--ink-3); }
.card__title { font-weight: 500; overflow-wrap: anywhere; }
.card__meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--ink-3); flex-wrap: wrap; }
.card__labels { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-block; font-size: 11px; line-height: 1; padding: 4px 7px; border-radius: 6px;
  background: color-mix(in srgb, var(--chip, #888) 18%, transparent);
  color: var(--ink-2); border: 1px solid color-mix(in srgb, var(--chip, #888) 45%, transparent);
}

.drag-ghost {
  position: fixed; z-index: 50; pointer-events: none; width: 260px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.35);
  cursor: grabbing; opacity: .95;
}

/* ---------- Quick add ---------- */
.quickadd {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.quickadd input, .quickadd select {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: 16px; border-radius: 6px; padding: 9px 12px; min-width: 0;
}
.quickadd input:focus, .quickadd select:focus { outline: none; border-color: var(--accent); }
.quickadd select { padding-right: 28px; background-image: none; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 500; border-radius: 6px; padding: 9px 14px;
  cursor: pointer;
}
.btn:hover { background: var(--paper-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- Dialogs ---------- */
.dialog {
  border: 0; padding: 0; background: transparent; max-width: none; max-height: none;
  width: 100%; height: 100%;
  place-items: end center;
}
.dialog:not([open]) { display: none; }
.dialog[open] { display: grid; animation: dialog-in .2s ease both; }
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px); } }
.dialog__body {
  width: min(560px, 100%); margin: 0;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px 10px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: 92dvh; overflow-y: auto;
}
@media (min-width: 720px) {
  .dialog { place-items: center; }
  .dialog__body { border-radius: 6px; padding-bottom: 18px; }
}
.dialog__title { margin: 0 0 6px; font-size: 18px; }
.dialog__lead { margin: 0 0 14px; color: var(--ink-2); font-size: 13.5px; }
.dialog__message { font-size: 13px; padding: 8px 10px; border-radius: 8px; margin: 6px 0; background: var(--paper-2); }
.dialog__message[data-kind="error"] { color: var(--danger); }
.dialog__message[data-kind="ok"] { color: var(--accent); }
.dialog__message[hidden] { display: none; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: 16px; border-radius: 6px; padding: 9px 12px;
}
.field textarea { resize: vertical; font-size: 14.5px; line-height: 1.55; font-family: var(--font-body); }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field__hint { font-size: 12px; color: var(--ink-3); margin: -6px 0 12px; }

.task__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--ink-3); }
.task__ghlink { color: var(--accent); text-decoration: none; font-size: 13px; }
.task__ghlink:hover { text-decoration: underline; }
.task__title { font-size: 17px !important; font-weight: 700; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--card); }
.segmented button {
  appearance: none; border: 0; background: none; color: var(--ink-2); font: inherit; font-size: 13.5px;
  padding: 8px 12px; cursor: pointer; border-right: 1px solid var(--line);
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; min-height: 22px; }
.chips .chip--empty { color: var(--ink-3); font-size: 12.5px; }

/* ---------- Empty / setup state ---------- */
.empty-state {
  grid-column: 1 / -1; align-self: center; justify-self: center; text-align: center;
  max-width: 420px; padding: 40px 20px; color: var(--ink-2);
}
.empty-state h2 { margin: 0 0 8px; color: var(--ink); font-size: 20px; }
.empty-state p { margin: 0 0 16px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); font-size: 13px; padding: 8px 14px; border-radius: 6px;
  z-index: 60; animation: toast-in .2s ease both;
  max-width: calc(100vw - 32px);
}
.toast--error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Card quick-done ---------- */
.card { position: relative; padding-right: 36px; }
.card__done {
  position: absolute; right: 6px; top: 6px; width: 24px; height: 24px;
  appearance: none; border: 1px solid var(--line); border-radius: 6px; background: var(--card);
  color: var(--ink-3); font-size: 13px; line-height: 1; cursor: pointer; opacity: 0;
  transition: opacity .12s ease;
}
.card:hover .card__done, .card:focus-within .card__done { opacity: 1; }
.card__done:hover { color: var(--col-done); border-color: var(--col-done); }
.card--done .card__done { opacity: 1; color: var(--col-done); border-color: transparent; background: none; }
@media (hover: none) { .card__done { opacity: .7; } }

/* ---------- Intake ---------- */
.intake__tools { display: flex; align-items: center; gap: 10px; margin: -4px 0 10px; }
.intake__message { font-size: 12.5px; color: var(--ink-3); }
.intake__list { display: flex; flex-direction: column; gap: 6px; max-height: 40dvh; overflow-y: auto; }
.intake__item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.intake__item input[type="text"] {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: 14px; border-radius: 6px; padding: 6px 9px; min-width: 0; width: 100%;
}
.intake__item select {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  font: inherit; font-size: 12.5px; border-radius: 6px; padding: 5px 8px;
}
.intake__item.is-off input[type="text"] { opacity: .45; text-decoration: line-through; }
.intake__note { font-size: 12px; color: var(--ink-3); grid-column: 2 / 4; margin-top: -4px; white-space: pre-wrap; }
