:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #8a8a85;
  --border: #e6e6e1;
  --hover: #f0f0ec;
  --accent: #1a1a1a;
  --accent-text: #ffffff;
  --high: #e5484d;
  --medium: #f5a524;
  --low: #8d8d86;
  --done: #30a46c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 1px rgba(0, 0, 0, .03);
  --radius: 10px;
  --backdrop: rgba(20, 20, 18, .35);
  --page-max: 1280px;
  --gutter: 24px;
  color-scheme: light;
}
/* Theme is set on <html data-theme> by a script in index.html (saved choice, else system). */
:root[data-theme="dark"] {
  --bg: #111110;
  --surface: #1b1b1a;
  --text: #ededec;
  --muted: #7c7c78;
  --border: #2a2a28;
  --hover: #232321;
  --accent: #ededec;
  --accent-text: #111110;
  --shadow: none;
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--high); margin: 0; font-size: 13px; }

/* ---------- Login ---------- */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.login-card p { margin: 0; }
.user-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); outline: none;
}
.login-card input:focus { border-color: var(--muted); }
.btn-primary {
  padding: 10px 12px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-weight: 500;
}
.pill {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface);
}
.pill.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ---------- Top bar ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
/* Same max-width and gutter as .board so the nav lines up with the columns. */
.topbar-inner {
  display: flex; align-items: center; gap: 16px;
  max-width: var(--page-max); margin: 0 auto; padding: 14px var(--gutter);
}
.brand { font-weight: 600; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 2px;
}
.tab:hover { background: var(--hover); color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); outline: 1px solid var(--border); }
.tab .you { color: var(--muted); font-size: 12px; }
.tab .count, h2 .count {
  margin-left: 6px; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.actions { display: flex; gap: 4px; }
.btn-ghost { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.btn-ghost:hover, .btn-ghost.active { background: var(--hover); color: var(--text); }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; }
.login-theme { position: fixed; top: 14px; right: 16px; }

/* ---------- Board ---------- */
.board {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px; padding: var(--gutter); max-width: var(--page-max); margin: 0 auto;
}
.board.with-done { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.column {
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
  border-radius: 12px; padding: 4px; margin: -4px; transition: background .12s;
}
.column.drop { background: var(--hover); }
.column h2 {
  margin: 0 0 4px; padding: 0 4px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--low); flex: none; }
.col-high .dot { background: var(--high); }
.col-medium .dot { background: var(--medium); }
.col-low .dot { background: var(--low); }
.col-done .dot { background: var(--done); }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; min-height: 8px; }
.empty { color: var(--muted); font-size: 13px; padding: 10px 4px; }
.list:has(.indicator) .empty { display: none; }
.indicator { height: 2px; border-radius: 2px; background: var(--text); opacity: .5; margin: -1px 0; }

.card {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 10px 10px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  cursor: grab;
}
.card.dragging { opacity: .35; }
.card .body { flex: 1; min-width: 0; }
.card .text { display: block; word-wrap: break-word; white-space: pre-wrap; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.col-done .card .text { color: var(--muted); text-decoration: line-through; }

.check {
  flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--muted) 60%, transparent); position: relative; transition: border-color .12s, background .12s;
}
.col-high .check { border-color: color-mix(in srgb, var(--high) 55%, transparent); }
.col-medium .check { border-color: color-mix(in srgb, var(--medium) 60%, transparent); }
.check:hover { border-color: var(--done); background: color-mix(in srgb, var(--done) 12%, transparent); }
.check.checked { background: var(--done); border-color: var(--done); }
.check.checked::after, .check:hover::after {
  content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px;
  border: solid var(--accent-text); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}
.check:not(.checked):hover::after { border-color: var(--done); }

.card { position: relative; }
.tools { display: flex; gap: 2px; margin: -3px -4px -3px 0; }
@media (hover: hover) {
  /* Desktop: float the buttons over the card on hover so they don't steal text width. */
  .tools {
    position: absolute; top: 6px; right: 6px; margin: 0; padding: 0 0 0 12px; visibility: hidden;
    background: linear-gradient(to right, transparent, var(--surface) 12px);
  }
  .card:hover .tools, .card:focus-within .tools { visibility: visible; }
}
.tools button {
  width: 24px; height: 24px; border-radius: 6px; color: var(--muted); font-size: 13px; line-height: 1;
}
.tools button:hover { background: var(--hover); color: var(--text); }
.tools .del:hover { color: var(--high); }

.add, .edit {
  width: 100%; padding: 9px 12px; border-radius: var(--radius);
  border: 1px dashed transparent; background: transparent; outline: none;
}
.add::placeholder { color: var(--muted); }
.add:hover { background: var(--hover); }
.add:focus { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.edit { padding: 0; border: 0; border-radius: 0; }

/* ---------- Menu ---------- */
.menu {
  position: absolute; z-index: 20; min-width: 140px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  display: flex; flex-direction: column;
}
.menu-title { font-size: 12px; color: var(--muted); padding: 4px 8px; }
.menu button { text-align: left; padding: 6px 8px; border-radius: 6px; }
.menu button:hover { background: var(--hover); }

/* ---------- Modal ---------- */
.modal {
  width: min(400px, calc(100vw - 32px)); padding: 20px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal::backdrop { background: var(--backdrop); }
.modal[open] { animation: pop .14s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.modal h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.modal p { margin: 0; color: var(--muted); word-wrap: break-word; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-actions button { padding: 8px 14px; }
.btn-primary.danger { background: var(--high); color: #fff; }

/* ---------- Offline ---------- */
.offline {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: var(--bg);
}
.offline-card {
  max-width: 320px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.offline-card svg { color: var(--muted); margin-bottom: 8px; }
.offline-card h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.offline-card p { margin: 0 0 12px; }
.offline-card .btn-primary { min-width: 140px; }
.offline-card .btn-primary:disabled { opacity: .6; cursor: default; }

/* ---------- Installed app (iPhone notch / home bar) ---------- */
.topbar { padding-top: env(safe-area-inset-top); }
.board { padding-bottom: calc(var(--gutter) + env(safe-area-inset-bottom)); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root { --gutter: 16px; }
  .topbar-inner { padding-top: 10px; padding-bottom: 10px; gap: 10px; flex-wrap: wrap; }
  .tabs { order: 3; flex-basis: 100%; }
  .actions { margin-left: auto; }
  .board, .board.with-done { grid-template-columns: 1fr; gap: 24px; }
}
