:root {
  --bg-app: #F7F8FA;
  --board-bg: #FFFFFF;
  --panel-bg: #F1F3F5;
  --border: #E3E6EA;
  --text: #1F2933;
  --text-muted: #6B7280;
  --axis: #C2C8D0;
  --crosshair: #D1D5DB;
  --link: #6366F1;
  --primary: #6366F1;
  --primary-hover: #4F46E5;

  --q-do-tint: #FDECEC;
  --q-schedule-tint: #EAF3FB;
  --q-delegate-tint: #FFF6E6;
  --q-eliminate-tint: #F2F3F5;

  --q-do: #DC2626;
  --q-schedule: #2563EB;
  --q-delegate: #D97706;
  --q-eliminate: #64748B;

  --pad: 24px;
  --card-w: 180px;
  --card-h: 64px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  min-width: 900px;
  background: var(--bg-app);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Roboto, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--board-bg);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-dot {
  width: 14px; height: 14px; border-radius: 4px;
  background: linear-gradient(135deg, var(--q-do), var(--primary));
}
.brand-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

.composer { display: flex; gap: 8px; flex: 1; max-width: 460px; }
.composer-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer-input::placeholder { color: #9AA3AF; }
.composer-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99,102,241,.25); }

.topbar-tools { display: flex; align-items: center; gap: 14px; margin-left: auto; }

.toggle { display: flex; align-items: center; gap: 6px; color: var(--text-muted); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--primary); width: 15px; height: 15px; cursor: pointer; }

.btn {
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: #F3F4F6; }

/* ---------- Board ---------- */
.board-pane { padding: 20px; min-height: 0; min-width: 0; }

.board {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 560px;
  min-height: 480px;
  padding: var(--pad);
  background: var(--board-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(16,24,40,.04);
  overflow: hidden;
  touch-action: none;
}

/* quadrant tints (each one quarter) */
.quad { position: absolute; width: 50%; height: 50%; pointer-events: none; }
.q-schedule  { top: 0;    left: 0;  background: var(--q-schedule-tint); }
.q-do        { top: 0;    right: 0; background: var(--q-do-tint); }
.q-eliminate { bottom: 0; left: 0;  background: var(--q-eliminate-tint); }
.q-delegate  { bottom: 0; right: 0; background: var(--q-delegate-tint); }

/* axes */
.axis { position: absolute; background: var(--axis); pointer-events: none; }
.axis-x { left: 0; right: 0; top: 50%; height: 2px; transform: translateY(-1px); }
.axis-y { top: 0; bottom: 0; left: 50%; width: 2px; transform: translateX(-1px); }
.axis-x::after {
  content: ""; position: absolute; right: -1px; top: 50%;
  transform: translateY(-50%);
  border-top: 6px solid transparent; border-bottom: 6px solid transparent;
  border-left: 9px solid var(--axis);
}
.axis-y::after {
  content: ""; position: absolute; left: 50%; top: -1px;
  transform: translateX(-50%);
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-bottom: 9px solid var(--axis);
}
.crosshair {
  position: absolute; left: 50%; top: 50%;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--crosshair);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* corner labels */
.corner {
  position: absolute;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted); opacity: .5;
  pointer-events: none;
}
.corner-tl { top: 14px; left: 18px; }
.corner-tr { top: 14px; right: 18px; }
.corner-bl { bottom: 30px; left: 18px; }
.corner-br { bottom: 30px; right: 18px; }

/* axis labels */
.axis-label { position: absolute; display: flex; align-items: center; gap: 8px; pointer-events: none; color: var(--text-muted); }
.axis-label .axis-name { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.axis-label .end-low, .axis-label .end-high { font-size: 10px; opacity: .7; }
.axis-label-x { left: 0; right: 0; bottom: 6px; justify-content: center; }
.axis-label-y {
  top: 0; bottom: 0; left: 4px;
  flex-direction: column-reverse; justify-content: center;
  writing-mode: vertical-rl; transform: rotate(180deg);
}

/* empty board hint */
.empty-board {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.empty-board p { margin: 0; text-align: center; color: var(--text-muted); font-size: 14px; line-height: 1.6; opacity: .85; }

/* ---------- Task card ---------- */
.task {
  position: absolute;
  top: 0; left: 0;
  width: var(--card-w);
  min-height: var(--card-h);
  padding: 11px 12px 11px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--q-eliminate);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(16,24,40,.06);
  z-index: 10;
  cursor: grab;
  will-change: transform;
  transition: box-shadow .15s ease;
}
.task:hover { box-shadow: 0 4px 12px rgba(16,24,40,.12); outline: 2px solid #fff; }
.task.dragging {
  cursor: grabbing;
  z-index: 1000;
  box-shadow: 0 10px 24px rgba(16,24,40,.20);
  transition: none;
}
.task:not(.dragging) { transition: box-shadow .15s ease, transform .12s cubic-bezier(.2,.7,.3,1); }
.task.linked { outline: 2px solid var(--link); }
.task.highlight { animation: pulse-ring .6s ease; }
.task.removing { opacity: 0; transform-origin: center; transition: opacity .15s ease; }

.task .card-title {
  padding-right: 26px;
  font-size: 14px; font-weight: 500; line-height: 1.35; color: var(--text);
  word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.task.done .card-title { text-decoration: line-through; color: var(--text-muted); }
.task.done { opacity: .55; background: #FAFBFC; border-left-color: #CBD5E1 !important; }

.title-input {
  display: block; width: 100%; max-width: 100%; box-sizing: border-box;
  font: inherit; font-size: 14px; font-weight: 500;
  border: 1px solid var(--primary); border-radius: 6px; padding: 3px 6px;
  outline: none; box-shadow: 0 0 0 2px rgba(99,102,241,.2);
}

/* View switcher — hidden on desktop, shown only inside the mobile query */
.view-switch { display: none; }

/* card controls */
.card-check, .card-del {
  flex: none; padding: 0; cursor: pointer; background: none; border: none;
}
.card-check {
  position: absolute; top: 11px; right: 11px;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #CBD5E1; background: #fff;
  transition: border-color .15s ease, background .15s ease;
}
.card-check:hover { border-color: var(--primary); }
.task.done .card-check { background: #46A758; border-color: #46A758; }
.task.done .card-check::after {
  content: ""; position: absolute; left: 5px; top: 1.5px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.card-del {
  position: absolute; top: 34px; right: 12px;
  width: 18px; height: 18px; line-height: 15px; text-align: center;
  font-size: 16px; color: var(--text-muted); border-radius: 4px;
  background: none; border: none; cursor: pointer;
  opacity: 0; transition: opacity .15s ease, background .15s ease, color .15s ease;
}
.task:hover .card-del { opacity: 1; }
.card-del:hover { background: #FEE2E2; color: var(--q-do); }
.card-check { padding: 0; cursor: pointer; }

/* ---------- Ranked side panel ---------- */
.panel {
  grid-column: 2; grid-row: 2;
  display: flex; flex-direction: column;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  min-height: 0;
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px; border-bottom: 1px solid var(--border);
}
.panel-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.panel-count {
  margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--primary);
  border-radius: 10px;
}
.ranked-list { flex: 1; overflow-y: auto; padding: 4px 0 16px; }

.list-empty { padding: 28px 18px; color: var(--text-muted); font-size: 13px; text-align: center; line-height: 1.6; }
.list-divider {
  margin: 10px 16px 4px; padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
}

.row {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px 11px; min-height: 52px;
  border-bottom: 1px solid #F1F5F9;
  cursor: pointer;
  transition: background .12s ease;
}
.row:hover { background: #EAEDF1; }
.row.linked { background: #EEF2FF; box-shadow: inset 3px 0 0 var(--link); }

.row-check {
  flex: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #CBD5E1; background: #fff; cursor: pointer; position: relative; padding: 0;
  transition: border-color .15s ease, background .15s ease;
}
.row-check:hover { border-color: var(--primary); }
.row.done .row-check { background: #46A758; border-color: #46A758; }
.row.done .row-check::after {
  content: ""; position: absolute; left: 4px; top: 1px;
  width: 3.5px; height: 7px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.row-rank { flex: none; width: 20px; font-size: 12px; font-weight: 700; color: var(--text-muted); font-variant-numeric: tabular-nums; text-align: right; }
.row-title { flex: 1; font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.done .row-title { text-decoration: line-through; color: var(--text-muted); }
.row-score {
  flex: none; min-width: 26px; height: 20px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.row.done .row-score { background: #9CA3AF !important; }
.row-del {
  flex: none; width: 18px; height: 18px; padding: 0; line-height: 16px; text-align: center;
  font-size: 15px; color: var(--text-muted); background: none; border: none; border-radius: 4px;
  opacity: 0; cursor: pointer; transition: opacity .15s ease, background .15s ease, color .15s ease;
}
.row:hover .row-del { opacity: 1; }
.row-del:hover { background: #FEE2E2; color: var(--q-do); }

.row-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: #E2E8F0; }
.row-bar-fill { height: 100%; border-radius: 0 2px 2px 0; }
.row.done .row-bar { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px);
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: 10px;
  background: #1E293B; color: #fff; font-size: 13px;
  box-shadow: 0 8px 24px rgba(16,24,40,.24);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
  z-index: 2000;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-undo { background: none; border: none; color: #A5B4FC; font: inherit; font-weight: 700; cursor: pointer; padding: 2px 4px; }
.toast-undo:hover { color: #C7D2FE; text-decoration: underline; }

/* ---------- Banners ---------- */
.banners { position: fixed; top: 0; left: 0; right: 0; z-index: 3000; }
.banner {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: #FEF3C7; color: #92400E; border-bottom: 1px solid #FDE68A;
  font-size: 13px;
}
.banner span { flex: 1; }
.banner-x { background: none; border: none; color: inherit; font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px; }

@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(99,102,241,.5); }
  100% { box-shadow: 0 0 0 14px rgba(99,102,241,0); }
}

@media (prefers-reduced-motion: reduce) {
  .task, .task:not(.dragging), .row, .toast, .composer-input, .btn { transition: none !important; }
  .task.highlight { animation: none; outline: 2px solid var(--link); }
}

/* ---------- Mobile / touch (phones + small portrait tablets) ---------- */
@media (max-width: 768px) {
  /* one column; relax desktop minimums */
  body {
    min-width: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
    height: 100dvh;
    /* smaller cards + gutter — drag math reads these from CSS, so it follows */
    --pad: 14px;
    --card-w: 140px;
    --card-h: 58px;
  }

  .topbar {
    grid-column: 1;
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    gap: 10px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .brand { order: 1; }
  .topbar-tools { order: 2; margin-left: auto; }
  .composer { flex: 1 1 100%; max-width: none; order: 3; }
  .view-switch { order: 4; display: inline-flex; }

  /* both panes share the single content cell; the body class chooses which shows */
  .board-pane, .panel { grid-column: 1; grid-row: 2; }
  body:not(.show-ranked) .panel { display: none; }
  body.show-ranked .board-pane { display: none; }
  .panel { border-left: none; border-top: 1px solid var(--border); }

  /* board fills the available column (no page scroll, max drag room) */
  .board-pane { padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .board {
    min-width: 0; min-height: 0;
    overscroll-behavior: none;
  }

  /* iOS focus auto-zoom defeat: any focused input >= 16px */
  .composer-input, .title-input { font-size: 16px; }
  .composer-input { height: 44px; }

  /* reclaim space on a small board */
  .corner { font-size: 10px; }
  .axis-label .axis-name { font-size: 10px; }

  /* card controls: side-by-side along the top, with ~44px tap pads that don't collide */
  .card-check { top: 10px; right: 10px; }
  .card-del { top: 10px; right: 38px; opacity: 1; }
  .card-check::before, .card-del::before { content: ""; position: absolute; inset: -13px; }
  .card-check, .card-del { user-select: none; }
  .card-title { padding-right: 64px; }

  /* ranked list: momentum + contained overscroll; bigger rows */
  .ranked-list { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .row { min-height: 56px; }
  .row-del { min-width: 44px; min-height: 44px; opacity: 1; }
  .row-del::before { content: ""; position: absolute; inset: -13px; }

  /* segmented control */
  .view-switch { background: #EEF0F3; border: 1px solid var(--border); border-radius: 9px; padding: 2px; gap: 2px; }
  .seg {
    min-height: 36px; padding: 0 14px;
    border: none; border-radius: 7px; background: transparent;
    color: var(--text-muted); font: inherit; font-weight: 600;
    cursor: pointer; touch-action: manipulation;
  }
  .seg[aria-selected="true"] { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(16,24,40,.10); }
  .seg-count {
    margin-left: 6px; min-width: 18px; padding: 0 5px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: #fff; background: var(--primary); border-radius: 9px;
  }

  /* kill the 300ms tap delay on top-bar controls */
  .topbar .btn, .composer-input, .toggle { touch-action: manipulation; }

  /* toast clears the home indicator */
  .toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
}

/* ---------- Touch capability (touch laptops / 2-in-1s at any width) ---------- */
@media (hover: none) {
  .card-del { opacity: 1; }
  .row-del { opacity: 1; }
  .task:hover { box-shadow: 0 1px 2px rgba(16,24,40,.06); outline: none; }
}
