:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #ebebe6;
  --text: #1c1d1f;
  --muted: #6b6d72;
  --border: #dcdcd6;
  --accent: #1c1d1f;
  --accent-text: #ffffff;
  --danger: #c2372c;
  --warn: #b86e00;
  --sacalma: #2563eb;
  --turmina: #d97706;
  --personal: #16a34a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 1px rgba(0, 0, 0, .04);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --surface: #222327;
    --surface-2: #2c2d32;
    --text: #ececec;
    --muted: #9a9ca3;
    --border: #34363c;
    --accent: #ececec;
    --accent-text: #17181b;
    --danger: #ef6b5f;
    --warn: #f0a33a;
    --sacalma: #5b8cff;
    --turmina: #f5a524;
    --personal: #3fc46f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { display: flex; flex-direction: column; }

button, input, textarea, select { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }

/* ── Header ─────────────────────────────────────────────── */

.top {
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-row { display: flex; align-items: center; gap: 12px; }
.top h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.top-actions { margin-left: auto; display: flex; gap: 6px; }
.top-actions form { margin: 0; }

.icon-btn { padding: 5px 9px; line-height: 1; font-size: 16px; }

.boards { flex-shrink: 0; }
.boards button { font-size: 14px; font-weight: 600; padding: 5px 11px; }
.icon-btn[aria-pressed="true"] { background: var(--surface-2); border-color: var(--muted); }

.areas { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.areas::-webkit-scrollbar { display: none; }

.chip {
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 13px;
  white-space: nowrap;
  background: transparent;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.capture { display: flex; gap: 8px; }
.capture input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 16px; /* avoids iOS zoom on focus */
}
.capture input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.capture button { border-radius: var(--radius); padding: 0 16px; }
.capture.busy button { opacity: .6; pointer-events: none; }

.col-tabs { display: none; }

/* ── Board ──────────────────────────────────────────────── */

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 12px;
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 16px);
  overflow-x: auto;
}

.column {
  flex: 1 0 250px;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border-radius: 12px;
  min-height: 0;
}

.column-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px 6px;
  font-weight: 600;
  font-size: 14px;
}
.column-head .count { color: var(--muted); font-weight: 500; font-size: 13px; }
.column-head .count.full { color: var(--warn); }
.column-head .hint { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 12px; }

.cards {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 60px;
}

.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 6px; }

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--area-color, var(--border));
  border-radius: 8px;
  padding: 8px 10px 8px 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.card[data-area="sacalma"] { --area-color: var(--sacalma); }
.card[data-area="turmina"] { --area-color: var(--turmina); }
.card[data-area="personal"] { --area-color: var(--personal); }

.card .title { font-size: 14px; word-wrap: break-word; padding-right: 22px; }
.card.stale { opacity: .7; }

.card .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 5px; font-size: 12px; color: var(--muted); }
.card .meta:empty { display: none; }
.badge-overdue { color: var(--danger); font-weight: 600; }
.badge-today { color: var(--warn); font-weight: 600; }
.steps-chip { font-variant-numeric: tabular-nums; }
.steps-chip.complete { color: var(--personal); font-weight: 600; }
.ai-pending { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.card .quick-done {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  font-size: 12px;
  line-height: 20px;
  color: var(--muted);
  background: transparent;
  opacity: 0;
}
.card:hover .quick-done { opacity: 1; }
.card .quick-done:hover { color: var(--personal); border-color: var(--personal); }
@media (hover: none) { .card .quick-done { display: none; } }

.card.new { animation: pop .9s ease; }
@keyframes pop { 0% { background: color-mix(in srgb, var(--card-accent, var(--area-color)) 25%, var(--surface)); } 100% { background: var(--surface); } }

/* ── Mobile: one column per screen, snap scrolling ──────── */

@media (max-width: 760px) {
  .top { padding-left: 16px; padding-right: 16px; }
  .top-row { flex-wrap: wrap; }
  .areas { order: 3; width: 100%; }
  .col-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .col-tabs::-webkit-scrollbar { display: none; }
  .col-tabs button { border: none; background: transparent; font-size: 13px; padding: 5px 9px; color: var(--muted); white-space: nowrap; }
  .col-tabs button.active { color: var(--text); background: var(--surface-2); font-weight: 600; }

  .board { scroll-snap-type: x mandatory; gap: 10px; }
  .column { flex: 0 0 calc(100vw - 44px); max-width: none; scroll-snap-align: center; }
}

/* ── Editor dialog ──────────────────────────────────────── */

dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }

#editor-form { display: flex; flex-direction: column; gap: 6px; }

#ed-title {
  font-size: 17px;
  font-weight: 600;
  border: none;
  resize: none;
  background: transparent;
  padding: 0;
  outline: none;
}

.field-label { font-size: 12px; color: var(--muted); margin-top: 8px; }

dialog input[type="text"], dialog input[type="date"], #ed-notes {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 16px;
}
#ed-notes { resize: vertical; }

.seg { display: flex; gap: 6px; }
.seg-wrap { flex-wrap: wrap; }
.seg button { font-size: 13px; padding: 6px 10px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.due-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.due-row input { flex: 1 1 150px; width: auto; }

.steps-list { list-style: none; margin: 2px 0 4px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.steps-list:empty { display: none; }
.step { display: flex; align-items: center; gap: 6px; }
.step input[type="checkbox"] { width: 18px; height: 18px; flex: none; accent-color: var(--personal); margin: 0; }
.step .step-title {
  flex: 1; min-width: 0; border: none; background: transparent; padding: 5px 4px;
  border-radius: 6px; font-size: 15px;
}
.step .step-title:focus { outline: none; background: var(--bg); }
.step.done .step-title { text-decoration: line-through; color: var(--muted); }
.step button { border: none; background: transparent; color: var(--muted); padding: 4px 6px; font-size: 13px; }
.step button:hover { color: var(--text); background: var(--surface-2); }
#ed-step-new {
  width: 100%; padding: 7px 10px; border: 1px dashed var(--border); border-radius: 8px;
  background: transparent; font-size: 15px;
}
.ed-more { margin-top: 10px; font-size: 13px; color: var(--muted); }
.ed-more summary { cursor: pointer; }
.demote-row { display: flex; gap: 6px; margin-top: 8px; }
.demote-row select {
  flex: 1; min-width: 0; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); font-size: 14px;
}

.ed-meta { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.ed-actions { display: flex; gap: 8px; margin-top: 14px; }
.spacer { flex: 1; }

/* ── Toast ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translate(-50%, 20px);
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  max-width: calc(100vw - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  display: flex;
  gap: 12px;
  align-items: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: transparent; color: inherit; border-color: currentColor; padding: 3px 9px; font-size: 13px; }

/* ── Life: column identity, project colours, motion ─────── */

[data-col="inbox"]   { --col: #8b5cf6; }
[data-col="next"]    { --col: #64748b; }
[data-col="doing"]   { --col: #f59e0b; }
[data-col="waiting"] { --col: #f97316; }
[data-col="done"]    { --col: #22c55e; }
[data-col="frozen"]  { --col: #06b6d4; }
:root { --yours: #ea580c; }
@media (prefers-color-scheme: dark) { :root { --yours: #fb923c; } }

.column {
  min-width: 0; /* one-line notes must ellipsize, not widen the column */
  background: color-mix(in srgb, var(--col) 6%, var(--surface-2));
  box-shadow: inset 0 3px 0 var(--col);
  transition: background .2s, box-shadow .2s;
}
.column-head { align-items: center; padding-top: 12px; }
.column-head .col-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--col);
  background: color-mix(in srgb, var(--col) 16%, transparent);
}
.column-head .count {
  padding: 1px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--col) 80%, var(--text));
  background: color-mix(in srgb, var(--col) 14%, transparent);
}
.column-head .count.full { color: var(--warn); }

.card {
  border-left: 4px solid var(--card-accent, var(--area-color, var(--border)));
  transition: transform .16s ease, box-shadow .16s ease;
}
@media (hover: hover) {
  .card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, .09); }
}
.card .note {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .project-tag { color: var(--text); font-weight: 600; display: inline-flex; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; flex-shrink: 0; }

.card.done { background: color-mix(in srgb, var(--surface) 65%, var(--surface-2)); box-shadow: none; }
.card.done .title { color: var(--muted); }
.card.done .title::before { content: "✓"; color: #22c55e; font-weight: 700; margin-right: 6px; }
.group-sep {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 8px 4px 0;
}
.group-sep:first-child { padding-top: 0; }

.card.yours { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--yours) 55%, transparent), var(--shadow); }
.badge-yours {
  background: var(--yours);
  color: #fff;
  font-weight: 600;
  padding: 0 7px;
  border-radius: 999px;
}
.badge-yours.long { background: var(--danger); }
.wait-long { color: var(--danger); font-weight: 600; }

.live { color: #b45309; font-weight: 600; display: inline-flex; align-items: center; }
@media (prefers-color-scheme: dark) { .live { color: #fbbf24; } }
.live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  background: #f59e0b;
  animation: live 1.8s ease-out infinite;
}
@keyframes live {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .55); }
  100% { box-shadow: 0 0 0 7px rgba(245, 158, 11, 0); }
}

.chip { display: inline-flex; align-items: center; }
.chip.mine { border-color: var(--yours); color: var(--yours); font-weight: 600; }
.chip.mine[aria-pressed="true"] { background: var(--yours); border-color: var(--yours); color: #fff; }
.areas { mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); padding-right: 28px; }

.col-tabs button.active { box-shadow: inset 0 -2px 0 var(--col); }

/* Entrance and landing */
.card.enter { animation: enter .42s cubic-bezier(.2, .8, .2, 1) backwards; animation-delay: calc(var(--i) * 28ms); }
@keyframes enter { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.card.landed { animation: landed 1s ease; }
@keyframes landed {
  0% { background: color-mix(in srgb, #22c55e 32%, var(--surface)); scale: 1.03; }
  100% { scale: 1; }
}

/* Drag: the card lifts and tilts, the target column lights up, the gap is a dashed slot */
body.dragging, body.dragging * { cursor: grabbing !important; }
.sortable-chosen { box-shadow: 0 0 0 2px color-mix(in srgb, var(--card-accent, var(--muted)) 60%, transparent); }
.sortable-fallback {
  /* The dragged copy must stick to the pointer: no inherited hover transition or entrance animation */
  transition: none !important;
  animation: none !important;
  opacity: 1 !important;
  rotate: 2.5deg;
  scale: 1.05;
  box-shadow: 0 22px 44px rgba(0, 0, 0, .25) !important;
  z-index: 1000;
}
.sortable-ghost {
  background: transparent !important;
  border: 2px dashed color-mix(in srgb, var(--col, var(--muted)) 70%, transparent) !important;
  box-shadow: none !important;
}
.sortable-ghost > * { visibility: hidden; }
body.dragging .card:hover { transform: none; box-shadow: var(--shadow); }
body.dragging .board { scroll-snap-type: none; } /* let auto-scroll carry the card to the next column */
.column.drop-target {
  background: color-mix(in srgb, var(--col) 16%, var(--surface-2));
  box-shadow: inset 0 3px 0 var(--col), inset 0 0 0 2px color-mix(in srgb, var(--col) 45%, transparent);
}

.confetti {
  position: fixed;
  width: 7px;
  height: 10px;
  margin: -5px 0 0 -3px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 1001;
  animation: confetti .85s cubic-bezier(.15, .7, .3, 1) forwards;
}
@keyframes confetti {
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Overview: one tile per project ─────────────────────── */

.board.overview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  align-content: start;
  gap: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-snap-type: none;
}
.summary {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  padding: 2px 2px 6px;
  font-size: 13px;
  color: var(--muted);
}
.summary b { font-size: 22px; color: var(--text); margin-right: 5px; font-variant-numeric: tabular-nums; }
.summary .doing b { color: #d97706; }
.summary .mine b { color: var(--yours); }
.summary .done b { color: #16a34a; }

.proj {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 14px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--pc);
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease;
}
.proj:focus-visible { outline: 2px solid var(--pc); outline-offset: 2px; }
@media (hover: hover) {
  .proj:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0, 0, 0, .1); }
}
.proj.quiet { opacity: .62; }
.proj.enter { animation: enter .45s cubic-bezier(.2, .8, .2, 1) backwards; animation-delay: calc(var(--i) * 35ms); }

.proj-head { display: flex; align-items: center; gap: 2px; min-width: 0; }
.proj-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-open { margin-left: auto; padding-left: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }

.bar { display: flex; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.bar span {
  min-width: 6px;
  background: var(--col);
  transform-origin: left;
  animation: grow .7s cubic-bezier(.2, .8, .2, 1) backwards;
  animation-delay: calc(var(--i) * 35ms + 150ms);
}
@keyframes grow { from { transform: scaleX(0); } }

.legend { display: flex; flex-wrap: wrap; gap: 3px 11px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; white-space: nowrap; }
.legend i { width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--col); }

.now { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.now li { display: flex; align-items: center; min-width: 0; }
.now li::before {
  content: "";
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: #f59e0b;
  animation: live 1.8s ease-out infinite;
}
.now .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.proj-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; font-size: 12px; color: var(--muted); }
.proj-foot .ago { margin-left: auto; }

@media (max-width: 760px) {
  .board.overview { grid-template-columns: 1fr; }
}
.col-tabs[hidden] { display: none !important; }
