:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --bg-softer: #283548;
  --line: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --waiting: #f59e0b;
  --working: #3b82f6;
  --complete: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: radial-gradient(1200px 800px at 80% -10%, #1e1b4b 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; font-weight: 700; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--bg-softer);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  transition: transform 0.1s, background 0.15s;
}
.btn:hover { background: #32415a; transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.15); }
.btn-ghost { background: transparent; border: none; color: var(--text-dim); padding: 4px 8px; }
.btn-ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); border-radius: 8px; }

.field {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.field:focus { border-color: var(--accent); }
textarea.field { resize: vertical; min-height: 80px; }
label.lbl { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 4px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { font-size: 19px; font-weight: 800; letter-spacing: 0.3px; }
.topbar .brand .bucket-emoji { margin-right: 6px; }
.topbar .spacer { flex: 1; }
.topbar .user-chip { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 14px; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex: none;
}
.avatar.sm { width: 22px; height: 22px; font-size: 9px; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { margin-left: -7px; border: 2px solid var(--bg-soft); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------- status colors ---------- */
.status-waiting { --status: var(--waiting); }
.status-working { --status: var(--working); }
.status-complete { --status: var(--complete); }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status, var(--text-dim));
  flex: none;
}
.status-working .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
}

/* ---------- board ---------- */
.quickadd {
  display: flex;
  gap: 10px;
  max-width: 680px;
  margin: 22px auto 8px;
  padding: 0 20px;
}
.quickadd .btn { white-space: nowrap; }
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
  padding: 18px 20px 60px;
  align-items: start;
}

.bucket-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.12s, border-color 0.15s;
}
.bucket-card:hover { border-color: var(--bucket-color, var(--accent)); }
.bucket-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 14px 10px;
  cursor: pointer;
  user-select: none;
}
.bucket-card.no-open .bucket-head { cursor: default; }
.bucket-head .bucket-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--bucket-color, var(--accent));
  flex: none;
}
.bucket-head h3 { font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bucket-head .count {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg);
  border-radius: 99px;
  padding: 2px 8px;
}
.bucket-head .open-hint { font-size: 11px; color: var(--text-dim); opacity: 0; transition: opacity 0.15s; }
.bucket-card:not(.no-open):hover .open-hint { opacity: 1; }

.bucket-progress { display: flex; height: 4px; background: var(--bg); }
.bucket-progress span { height: 100%; transition: width 0.4s; }
.bucket-progress .seg-complete { background: var(--complete); }
.bucket-progress .seg-working { background: var(--working); }
.bucket-progress .seg-waiting { background: var(--waiting); }

.chip-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg-softer);
  border: 1px solid var(--line);
  border-left: 3px solid var(--status, var(--text-dim));
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  cursor: grab;
  transition: background 0.12s;
}
.chip:hover { background: #324158; }
.chip:active { cursor: grabbing; }
.chip .chip-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.is-complete .chip-title { color: var(--text-dim); }
.chip .check { color: var(--complete); font-size: 12px; }

.bucket-card.is-trash { opacity: 0.85; border-style: dashed; }
.bucket-card.is-trash .chip { border-left-color: var(--text-dim); opacity: 0.75; }

.new-bucket {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  transition: border-color 0.15s, color 0.15s;
}
.new-bucket:hover { border-color: var(--accent); color: var(--text); }

/* drag feedback */
.sortable-ghost { opacity: 0.35; }
.sortable-drag { box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5); }
.chip-list.drag-over, .t-col-list.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 10px; }

/* ---------- timeline page ---------- */
.timeline-wrap {
  display: flex;
  gap: 16px;
  padding: 18px 20px 40px;
  align-items: flex-start;
  overflow-x: auto;
  min-height: calc(100vh - 60px);
}
.t-col {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 300px;
  flex: none;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 110px);
}
.t-col.backlog { border-style: dashed; background: rgba(30, 41, 59, 0.55); }
.t-col.complete { border-color: rgba(34, 197, 94, 0.45); }
.t-col.complete .col-head h3 { color: var(--complete); }
.col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: grab;
  user-select: none;
}
.t-col.backlog .col-head, .t-col.complete .col-head { cursor: default; }
.col-head h3 { font-size: 14px; flex: 1; }
.col-head .count { font-size: 12px; color: var(--text-dim); }
.t-col-list {
  list-style: none;
  margin: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 80px;
}
.task {
  background: var(--bg-softer);
  border: 1px solid var(--line);
  border-top: 3px solid var(--status, var(--text-dim));
  border-radius: 11px;
  padding: 11px 12px;
  cursor: grab;
  transition: background 0.12s, transform 0.12s;
}
.task:hover { background: #324158; transform: translateY(-1px); }
.task .task-title { font-size: 14px; font-weight: 600; margin-bottom: 7px; }
.task.is-complete .task-title { color: var(--text-dim); text-decoration: line-through; }
.task .task-meta { display: flex; align-items: center; gap: 8px; }
.task .task-meta .dot { margin-right: auto; }
.add-col {
  flex: none;
  width: 220px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 20px;
  background: transparent;
  color: var(--text-dim);
  font-weight: 600;
}
.add-col:hover { border-color: var(--accent); color: var(--text); }

.legend { display: flex; gap: 14px; align-items: center; font-size: 12.5px; color: var(--text-dim); }
.legend .dot { width: 8px; height: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- auth screens ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 24px; margin-bottom: 4px; }
.auth-card .sub { color: var(--text-dim); font-size: 14px; margin: 0 0 18px; }
.auth-card .btn-primary { width: 100%; margin-top: 18px; padding: 11px; }
.qr-box {
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  width: fit-content;
  margin: 14px auto;
}
.secret-code {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  text-align: center;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px;
  margin-top: 8px;
}
.code-input { text-align: center; font-size: 22px; letter-spacing: 8px; font-family: ui-monospace, monospace; }

/* ---------- modals ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal.wide { max-width: 720px; }
.modal h2 { font-size: 18px; margin-bottom: 6px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal .modal-actions .spacer { flex: 1; }

.assignee-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.assignee-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 5px 12px 5px 6px;
  cursor: pointer;
  font-size: 13px;
  background: var(--bg);
  transition: border-color 0.12s, background 0.12s;
}
.assignee-pill.on { border-color: var(--accent); background: rgba(99, 102, 241, 0.18); }

.color-row { display: flex; gap: 8px; margin-top: 6px; }
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
}
.swatch.on { border-color: #fff; }

.people-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 10px; }
.people-table th { text-align: left; color: var(--text-dim); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.people-table td { padding: 8px; border-bottom: 1px solid rgba(51, 65, 85, 0.5); }
.people-table .inactive { opacity: 0.45; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--text-dim); }
.tag.admin { color: var(--accent-2); border: 1px solid var(--accent-2); }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#toast.show { opacity: 1; }
#toast.ok { background: var(--complete); color: #052e16; font-weight: 600; }

.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }
.hidden { display: none !important; }

#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 300; }
