:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --col: #eeece7;
  --ink: #1a1a19;
  --ink-2: #5d5b55;
  --ink-3: #8f8c84;
  --line: #e2dfd8;
  --line-2: #d4d0c6;
  --accent: #1a1a19;
  --accent-ink: #ffffff;
  --todo: #6b7280;
  --doing: #d97706;
  --done: #16a34a;
  --danger: #c2410c;
  --danger-bg: #fff4ed;
  --shadow: 0 1px 2px rgba(26, 26, 25, .06), 0 1px 1px rgba(26, 26, 25, .04);
  --shadow-lift: 0 12px 28px -8px rgba(26, 26, 25, .22), 0 2px 6px rgba(26, 26, 25, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1d1d1b;
    --col: #181816;
    --ink: #f1efe9;
    --ink-2: #b2afa6;
    --ink-3: #807d75;
    --line: #2b2a27;
    --line-2: #3a3935;
    --accent: #f1efe9;
    --accent-ink: #121211;
    --todo: #9ca3af;
    --doing: #f59e0b;
    --done: #22c55e;
    --danger: #fb923c;
    --danger-bg: #2a1a10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lift: 0 14px 30px -8px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* leave the bottom-right corner to the host badge */
  padding-bottom: 72px;
}
button, input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1240px; margin: 0 auto; padding: 22px 24px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 40px; height: 40px; border-radius: 11px; background: var(--ink);
  display: flex; align-items: flex-start; justify-content: center; gap: 3px; padding: 9px 8px; flex: none;
}
.logo i { width: 6px; border-radius: 2px; background: var(--bg); display: block; }
.logo i:nth-child(1) { height: 22px; }
.logo i:nth-child(2) { height: 15px; opacity: .7; }
.logo i:nth-child(3) { height: 9px; opacity: .45; }
h1 { margin: 0; font-size: 21px; letter-spacing: -.02em; line-height: 1.15; }
.sync { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.sync.live .dot { background: var(--done); box-shadow: 0 0 0 3px color-mix(in srgb, var(--done) 20%, transparent); }
.sync.err .dot { background: var(--danger); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.who { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.who a { color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.who a:hover { text-decoration-color: currentColor; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: transform .08s ease, background .15s ease, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { opacity: .9; }
.btn.ghost { background: transparent; border-color: var(--line-2); }
.btn.ghost:hover { background: var(--col); }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.danger:hover { background: var(--danger-bg); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center; color: var(--ink-2);
}
.icon-btn:hover { background: var(--col); color: var(--ink); }

/* ---------- board ---------- */
.board {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px;
  max-width: 1240px; margin: 0 auto; padding: 0 24px;
}
.col {
  background: var(--col); border-radius: 18px; padding: 12px; min-height: 420px;
  display: flex; flex-direction: column; border: 1px solid transparent; transition: border-color .15s, background .15s;
}
.col > header { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; }
.col h2 { margin: 0; font-size: 13.5px; font-weight: 650; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.pip { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.col[data-status="todo"] { --c: var(--todo); }
.col[data-status="doing"] { --c: var(--doing); }
.col[data-status="done"] { --c: var(--done); }
.col > header b, .tabs b {
  font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface);
  border-radius: 999px; padding: 1px 9px; min-width: 26px; text-align: center; font-variant-numeric: tabular-nums;
}
.col.over { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, var(--col)); }

.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.empty {
  border: 1.5px dashed var(--line-2); border-radius: 12px; padding: 22px 12px; text-align: center;
  color: var(--ink-3); font-size: 13px;
}

.card {
  position: relative; background: var(--surface); border-radius: var(--radius); padding: 12px 12px 10px 14px;
  box-shadow: var(--shadow); border: 1px solid var(--line); cursor: grab; outline: none;
  transition: box-shadow .15s, transform .15s, opacity .15s;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--c);
}
.card:hover { box-shadow: var(--shadow-lift); }
.card:focus-visible { box-shadow: 0 0 0 2px var(--ink); }
.card.dragging { opacity: .4; }
.card.flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 45%, transparent); } 100% { box-shadow: var(--shadow); } }
.card h3 { margin: 0 0 4px; font-size: 14.5px; font-weight: 600; line-height: 1.35; letter-spacing: -.005em; word-wrap: break-word; }
.col[data-status="done"] .card h3 { color: var(--ink-2); }
.card .notes {
  margin: 0 0 10px; font-size: 13px; color: var(--ink-2); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-wrap: break-word;
}
.card .meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-3); }
.avatar {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 10px; font-weight: 700; color: #fff; letter-spacing: .02em;
}
.avatar.none { background: var(--col); color: var(--ink-3); border: 1px dashed var(--line-2); }
.meta .name { color: var(--ink-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.meta .when { margin-left: auto; white-space: nowrap; }
.moves { display: flex; gap: 2px; margin-left: 4px; }
.moves button {
  width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-3);
  display: grid; place-items: center; cursor: pointer;
}
.moves button:hover { background: var(--col); color: var(--ink); }
.moves svg { width: 15px; height: 15px; }

.loading { text-align: center; color: var(--ink-3); font-size: 14px; }

/* ---------- tabs (phones) ---------- */
.tabs { display: none; }

/* ---------- dialogs ---------- */
dialog {
  border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--ink);
  width: min(520px, calc(100vw - 32px)); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45);
}
dialog::backdrop { background: rgba(20, 20, 18, .42); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.sheet { padding: 20px 22px 20px; display: flex; flex-direction: column; gap: 14px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h3 { margin: 4px 0 0; font-size: 18px; letter-spacing: -.015em; line-height: 1.3; word-wrap: break-word; min-width: 0; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.sheet-foot.split { justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field legend, .field .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); padding: 0; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line-2); background: var(--bg); border-radius: 10px;
  padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 10%, transparent); background: var(--surface); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--col); padding: 4px; border-radius: 11px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span, .seg button {
  display: block; width: 100%; text-align: center; padding: 7px 6px; border-radius: 8px; border: 0; background: transparent;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.seg input:checked + span, .seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--ink); }
.d-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 13px; color: var(--ink-2); }
.d-meta .chip { display: inline-flex; align-items: center; gap: 7px; }
.d-notes {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14px;
  white-space: pre-wrap; word-wrap: break-word; max-height: 40vh; overflow: auto; color: var(--ink);
}
.d-notes.empty-notes { color: var(--ink-3); font-style: italic; }
.form-error {
  margin: 0; background: var(--danger-bg); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  border-radius: 10px; padding: 10px 12px; font-size: 13.5px; line-height: 1.45;
}
.form-error a { color: inherit; font-weight: 700; }

/* ---------- toasts (top, away from the badge) ---------- */
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow-lift); animation: pop .18s ease;
}
.toast a { color: inherit; font-weight: 700; }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .top { padding: 16px 16px 12px; }
  h1 { font-size: 19px; }
  .logo { width: 36px; height: 36px; padding: 8px 7px; }
  .logo i:nth-child(1) { height: 20px; }
  .who { max-width: 130px; font-size: 12.5px; }
  .who .long { display: none; }
  .btn#new-btn span { display: none; }
  .btn#new-btn { width: 40px; padding: 0; }
  .tabs {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 0 16px 12px; padding: 4px;
    background: var(--col); border-radius: 12px; position: sticky; top: 8px; z-index: 5;
  }
  .tabs button {
    border: 0; background: transparent; border-radius: 9px; padding: 8px 4px; font-weight: 600; font-size: 13.5px;
    color: var(--ink-2); display: flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  }
  .tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  .tabs b { background: var(--col); }
  .tabs button.active b { background: var(--bg); }
  .board { grid-template-columns: 1fr; padding: 0 16px; }
  .col { display: none; min-height: 300px; }
  .board[data-tab="todo"] .col[data-status="todo"],
  .board[data-tab="doing"] .col[data-status="doing"],
  .board[data-tab="done"] .col[data-status="done"] { display: flex; }
  .col > header { display: none; }
  .card { cursor: pointer; }
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 92vh; }
  dialog[open] { animation: up .22s ease; }
  @keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
  .sheet { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
