/* Kanban on Pagelove — design tokens + layout.
   No inline styles anywhere: the page ships a strict CSP (style-src 'self'),
   which also neutralizes style attributes in visitor-posted card HTML. */

:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --bg-accent: radial-gradient(1200px 500px at 70% -10%, #eceaf6 0%, transparent 60%);
  --ink: #1c1e24;
  --ink-soft: #585d66;
  --column-bg: #edebe6;
  --column-border: #e2dfd8;
  --card-bg: #ffffff;
  --card-border: #e6e3dc;
  --card-shadow: 0 1px 2px rgba(20, 22, 30, 0.08), 0 2px 8px rgba(20, 22, 30, 0.06);
  --card-shadow-lift: 0 8px 18px rgba(20, 22, 30, 0.18), 0 2px 6px rgba(20, 22, 30, 0.12);
  --accent-todo: #d97706;
  --accent-doing: #2563eb;
  --accent-done: #16a34a;
  --focus-ring: #2563eb;
  --danger: #dc2626;
  --toast-bg: #24262c;
  --toast-ink: #f3f2ee;
  --radius-col: 14px;
  --radius-card: 9px;
  --gap: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121317;
    --bg-accent: radial-gradient(1200px 500px at 70% -10%, #1a1c2a 0%, transparent 60%);
    --ink: #e9e7e1;
    --ink-soft: #9aa0ab;
    --column-bg: #1b1d22;
    --column-border: #262931;
    --card-bg: #24262d;
    --card-border: #30333c;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    --card-shadow-lift: 0 10px 22px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
    --accent-todo: #f59e0b;
    --accent-doing: #60a5fa;
    --accent-done: #4ade80;
    --focus-ring: #60a5fa;
    --danger: #f87171;
    --toast-bg: #e9e7e1;
    --toast-ink: #1c1e24;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg-accent), var(--bg);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
}

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

/* ---------- Progressive enhancement ----------
   Without JavaScript the raw card list IS the page: real, readable content
   rather than an empty board. With JavaScript the list becomes the data store
   and the board is rendered from it. The .js flag is set render-blocking in
   <head>, so the right layout is chosen before first paint. */

#pl-cards {
  list-style: none;
  margin: 0;
  padding: 0 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-width: 46rem;
}

#pl-cards > li.card { cursor: default; }

#pl-cards > li.card::before {
  content: attr(data-lane);
  display: inline-block;
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-right: 0.6rem;
}

html.js #pl-cards { display: none; }
html:not(.js) main { display: none; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem 0.75rem;
}

.topbar h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.topbar form {
  display: flex;
  gap: 0.5rem;
  flex: 1 1 16rem;
  max-width: 30rem;
}

.topbar input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.8rem;
  font: inherit;
  color: inherit;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
}

.topbar input[type="text"]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.topbar form button {
  padding: 0.5rem 1.1rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent-doing);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.topbar form button:hover { filter: brightness(1.08); }
.topbar form button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- Status badge ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-left: auto;
  white-space: nowrap;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-soft);
}

.status[data-state="live"] .status-dot { background: var(--accent-done); }
.status[data-state="connecting"] .status-dot,
.status[data-state="reconnecting"] .status-dot { background: var(--accent-todo); }
.status[data-state="preview"] .status-dot { background: var(--ink-soft); }
.status[data-state="error"] .status-dot { background: var(--danger); }

/* ---------- Board & columns ---------- */

main {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
  padding: 0.75rem 1.5rem 1.5rem;
  flex: 1;
  overflow-x: auto;
  scroll-snap-type: x proximity;
}

.column {
  background: var(--column-bg);
  border: 1px solid var(--column-border);
  border-radius: var(--radius-col);
  padding: 0.85rem;
  width: 19rem;
  min-width: 16.5rem;
  flex-shrink: 0;
  scroll-snap-align: start;
  max-height: 100%;
  display: flex;
  flex-direction: column;
}

.column-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0.25rem 0.75rem;
}

.column-head h2 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.column-head h2::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 3px;
  flex-shrink: 0;
}

.column[data-lane="todo"] .column-head h2::before { background: var(--accent-todo); }
.column[data-lane="doing"] .column-head h2::before { background: var(--accent-doing); }
.column[data-lane="done"] .column-head h2::before { background: var(--accent-done); }

.count {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  min-width: 1.6rem;
  text-align: center;
}

.card-list {
  list-style: none;
  margin: 0;
  /* Padding keeps a card's 2px focus ring (offset 2px) inside the scroll clip. */
  padding: 5px;
  min-height: 3.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow-y: auto;
  border-radius: 8px;
  outline: 2px dashed transparent;
  outline-offset: -1px;
  transition: outline-color 120ms ease, background-color 120ms ease;
}

.card-list:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.card-list.drag-over {
  outline-color: var(--focus-ring);
  background: color-mix(in srgb, var(--focus-ring) 8%, transparent);
}

.card-list[data-empty="true"]::after {
  content: "Drop cards here";
  display: grid;
  place-items: center;
  min-height: 3rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  border: 1.5px dashed var(--column-border);
  border-radius: var(--radius-card);
}

.card-list.drag-over[data-empty="true"]::after {
  border-color: var(--focus-ring);
  color: var(--focus-ring);
}

/* A card the app did not build (posted through the raw API in an unexpected
   shape). Shown, because it is real content someone added, but not interactive
   and never the subject of a write. */
.card[data-foreign="true"] {
  cursor: default;
  opacity: 0.8;
  border-style: dashed;
}

/* ---------- Cards ---------- */

.card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 0.6rem 0.7rem;
  box-shadow: var(--card-shadow);
  cursor: grab;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  /* Both pan axes stay native (so the board can be swiped horizontally from a
     card); the long-press handler preventDefaults once a drag actually starts.
     `manipulation` still suppresses double-tap zoom, which would otherwise
     fight double-click-to-rename. */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: box-shadow 140ms ease, border-color 140ms ease;
}

.card:hover { box-shadow: var(--card-shadow-lift); }

.card:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.card-text {
  flex: 1;
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  gap: 0.15rem;
  opacity: 0;
  transition: opacity 120ms ease;
}

.card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; }

@media (hover: none) {
  .card-actions { opacity: 0.7; gap: 0.55rem; }
}

.card-actions button {
  position: relative;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.2rem 0.3rem;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

/* Extend the hit area to ~36px without inflating card height. */
.card-actions button::before {
  content: "";
  position: absolute;
  inset: -8px -5px;
}

.card-actions button:hover { background: var(--column-bg); color: var(--ink); }
.card-edit:hover { color: var(--accent-doing); }
.card-delete:hover { color: var(--danger); }
.card-actions button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  opacity: 1;
}

/* Editing state */

.card.editing { cursor: text; }

.card.editing .card-text {
  user-select: text;
  -webkit-user-select: text;
  outline: none;
  box-shadow: inset 0 -2px 0 var(--accent-doing);
}

/* Drag states */

.card.placeholder {
  opacity: 0.45;
  border-style: dashed;
  box-shadow: none;
  cursor: grabbing;
}

.card.ghost {
  position: fixed;
  z-index: 1000;
  margin: 0;
  pointer-events: none;
  box-shadow: var(--card-shadow-lift);
  opacity: 0.95;
  cursor: grabbing;
  left: 0;
  top: 0;
  will-change: transform;
}

/* Keyboard lift */

.card.kbd-lift {
  outline: 2px solid var(--accent-todo);
  outline-offset: 2px;
  box-shadow: var(--card-shadow-lift);
}

/* Remote-change flash */

.card.remote-flash {
  animation: remote-flash 900ms ease-out;
}

@keyframes remote-flash {
  0% { border-color: var(--focus-ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 35%, transparent); }
  100% { border-color: var(--card-border); box-shadow: var(--card-shadow); }
}

/* ---------- Toasts ---------- */

/* Class-based, never id-based: a visitor-posted card carrying id="toasts"
   would otherwise inherit these styles and paint a fixed overlay. */
.toast-stack {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 2000;
  pointer-events: none;
  max-width: min(92vw, 34rem);
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 0.85rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  box-shadow: var(--card-shadow-lift);
  max-width: 100%;
}

.toast.has-action { pointer-events: auto; }

.toast-action {
  flex-shrink: 0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 6px;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}

.toast-action:hover { background: color-mix(in srgb, currentColor 15%, transparent); }
.toast-action:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .topbar { padding: 0.75rem 1rem 0.5rem; gap: 0.75rem; }
  main { padding: 0.5rem 1rem 1rem; }
  .column { width: 82vw; min-width: 82vw; }
  .status .status-text { display: none; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
