/* ---------- Fonts ---------- */
@font-face {
  font-family: "Agrandir Wide";
  src: url("fonts/agrandir-wide.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

/* ---------- Design tokens ---------- */
:root {
  /* Neutrals — light mode */
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #fafaf9;
  --text: #1a1a19;
  --muted: #6b6b68;
  --faint: #9a9a96;
  --border: rgba(0, 0, 0, 0.10);
  --border-strong: rgba(0, 0, 0, 0.18);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);

  /* Quadrant colors: light (resting) / dark (selected) */
  --hu-light: #F6C9CB; --hu-dark: #C85A63;
  --hn-light: #F7E2A9; --hn-dark: #C79A2E;
  --lu-light: #CBDFF2; --lu-dark: #4C86BC;
  --ln-light: #D2E7CE; --ln-dark: #5E9457;

  --radius: 10px;
  --radius-lg: 16px;
  --font-head: "Agrandir Wide", "Montserrat", system-ui, sans-serif;
  --font-body: "Montserrat", system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0e0e0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text: #f2f2f0;
  --muted: #a3a39d;
  --faint: #74746f;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.20);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
#app {
  max-width: 1040px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 20px) 20px 40px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.greeting {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(24px, 5vw, 38px);
  line-height: 1.05;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.clock { color: var(--muted); font-size: 14px; font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.ghost-btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { border-color: var(--border-strong); }
.folder-icon { display: inline-block; vertical-align: -2px; color: var(--muted); }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { border-color: var(--border-strong); }

/* ---------- Filter row (back + name + filters) ---------- */
.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-bottom: 22px;
}
.back-btn {
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 22px; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.back-btn:hover { border-color: var(--border-strong); }
.view-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  margin-right: 2px;
}
.filters {
  position: relative;
  display: inline-flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.filter {
  position: relative;
  z-index: 1;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 6px 16px;
  cursor: pointer;
  transition: color 0.15s;
}
.filter.is-active { color: var(--text); background: transparent; }

/* Sliding highlight thumb (filters + toggles) */
.pill-thumb {
  position: absolute;
  top: 0; left: 0;
  border-radius: 999px;
  z-index: 0;
  pointer-events: none;
  transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1), width 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}
.filters .pill-thumb { background: var(--bg); }
.toggle .pill-thumb { background: var(--text); }
.filters .e { font-size: 12px; margin-left: 3px; filter: grayscale(1); }

/* ---------- Board / quadrants ---------- */
.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
/* High-priority row is double the height of the low-priority row */
.board .quad-HU, .board .quad-HN { min-height: 300px; }
.board .quad-LU, .board .quad-LN { min-height: 150px; }
.quadrant {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  min-height: 150px;
}
.quad-header {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 2px 4px 12px;
  padding: 4px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-user-select: none;
  user-select: none;
}
.quad-header:hover { background: var(--surface-2); }
.quad-header:hover .quad-expand { opacity: 1; }
.quad-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.quad-title { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.quad-sub { font-size: 11px; color: var(--faint); font-weight: 500; margin-left: auto; }
.quad-expand { font-size: 13px; color: var(--faint); opacity: 0; transition: opacity 0.15s; margin-left: 8px; }

/* ---------- Full-page quadrant detail view ---------- */
.detail-view { min-height: 60vh; }
.detail-view .quadrant {
  min-height: 60vh;
  border-radius: var(--radius-lg);
}
.detail-view .quad-header { cursor: default; }
.detail-view .quad-header:hover { background: transparent; }
.detail-view .quad-expand { display: none; }

/* Back arrow lives inside the quadrant, left of its heading */
.quad-back {
  width: 30px; height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-right: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.quad-back:hover { border-color: var(--border-strong); background: var(--surface-2); }

.quad-HU .quad-swatch { background: var(--hu-dark); }
.quad-HN .quad-swatch { background: var(--hn-dark); }
.quad-LU .quad-swatch { background: var(--lu-dark); }
.quad-LN .quad-swatch { background: var(--ln-dark); }

.task-list { display: flex; flex-direction: column; }

/* ---------- Task row (minimal line, no box) ---------- */
.card {
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
}
.card-main { display: flex; align-items: center; gap: 10px; }

.checkbox {
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 1.6px solid var(--border-strong);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
}
.checkbox::after { content: "✓"; font-size: 12px; color: #fff; opacity: 0; transform: scale(0.6); transition: opacity 0.12s, transform 0.12s; }
.card.done .checkbox { background: var(--text); border-color: var(--text); }
.card.done .checkbox::after { opacity: 1; transform: scale(1); }
:root[data-theme="dark"] .card.done .checkbox::after { color: var(--bg); }

/* Bigger expand arrow, on the left */
.caret-btn {
  border: none; background: transparent; cursor: pointer;
  color: var(--muted); padding: 0; flex-shrink: 0;
  display: inline-flex; align-items: center;
}
.caret-btn .caret { display: inline-block; font-size: 16px; line-height: 1; transition: transform 0.2s ease; }
.card.expanded .caret-btn .caret { transform: rotate(90deg); }

.title {
  flex: 1;
  position: relative;
  font-size: 14px;
  line-height: 1.35;
  outline: none;
  cursor: default;
  word-break: break-word;
  min-width: 0;
  transition: color 0.28s ease;
}
.card.done > .card-main > .title { color: var(--faint); }
/* animated strike-through */
.card > .card-main > .title::after {
  content: ""; position: absolute; left: 0; top: 50%;
  height: 1.5px; width: 0; background: var(--faint);
  transition: width 0.28s ease;
}
.card.done > .card-main > .title::after { width: 100%; }
.title[contenteditable="true"] { cursor: text; }
.title[contenteditable="true"]::after { display: none; }

/* count (right of title) + biz-type label (right border) */
.count { font-size: 11px; color: var(--faint); font-weight: 600; flex-shrink: 0; }
.biz-label {
  font-size: 11px; color: var(--faint); font-weight: 500;
  white-space: nowrap; flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 4px;
}
.biz-label .e { font-size: 12px; filter: grayscale(1); }

.menu-btn {
  border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1;
  padding: 0 2px; flex-shrink: 0; letter-spacing: 1px;
}

/* Drag-to-reorder handle (far right of each incomplete task) */
.drag-handle {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 2px 2px 4px;
  color: var(--faint);
  cursor: grab;
  touch-action: none;               /* vertical drag reorders instead of scrolling */
  transition: color 0.15s;
}
.drag-handle:hover { color: var(--muted); }
.drag-handle svg line { stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.card.dragging {
  background: var(--surface-2);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
  position: relative;
  z-index: 5;
  cursor: grabbing;
}
.card.dragging .drag-handle { cursor: grabbing; }
:root[data-theme="dark"] .card.dragging { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); }

/* Subtasks */
.subs {
  margin: 8px 0 2px 30px;
  display: flex; flex-direction: column; gap: 6px;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}
.sub { display: flex; align-items: center; gap: 8px; }
.sub .checkbox { width: 17px; height: 17px; border-radius: 5px; }
.sub .checkbox::after { font-size: 10px; }
.sub.done .checkbox { background: var(--text); border-color: var(--text); }
.sub.done .checkbox::after { opacity: 1; transform: scale(1); }
:root[data-theme="dark"] .sub.done .checkbox::after { color: var(--bg); }
.sub .title { font-size: 13px; }
.sub.done .title { text-decoration: line-through; color: var(--faint); }

.add-row {
  border: none; background: transparent; cursor: pointer;
  color: var(--faint); font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 2px; text-align: left; width: 100%;
  font-family: var(--font-body);
}
.add-row:hover { color: var(--muted); }
.add-row .plus { font-size: 15px; }
.add-task-row { margin-top: 4px; }
.add-sub-row { padding-left: 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 720px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-title {
  font-family: var(--font-head);
  font-weight: 700; font-size: 22px;
  margin: 0 0 20px;
}
.form-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 28px; }
.form-left { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.text-input {
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 13px;
  outline: none; width: 100%; resize: none;
}
.text-input:focus { border-color: var(--border-strong); }

.toggle {
  position: relative;
  display: flex; gap: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px;
}
.seg {
  position: relative;
  z-index: 1;
  font-family: var(--font-body); font-size: 13px; font-weight: 500;
  color: var(--muted); background: transparent; border: none;
  border-radius: 999px; padding: 8px 16px; cursor: pointer;
  transition: color 0.18s;
  flex: 1; white-space: nowrap;
}
.seg.is-active { background: transparent; color: var(--surface); }

/* Quadrant picker */
.form-right { display: flex; flex-direction: column; gap: 8px; }
.quad-picker {
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 8px; flex: 1; min-height: 200px;
}
.quad-cell {
  position: relative;
  border: 2px solid transparent; border-radius: var(--radius);
  cursor: pointer; padding: 12px;
  display: flex; align-items: flex-end;
  font-family: var(--font-body);
  transition: background 0.2s;
}
.quad-cell .q-name { font-size: 12px; font-weight: 600; line-height: 1.25; text-align: left; }
.quad-cell .q-tick {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: #fff;
  opacity: 0; transform: scale(0.6);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.quad-cell.is-selected .q-tick { opacity: 1; transform: scale(1); }
.quad-cell[data-quad="HU"] { background: var(--hu-light); color: var(--hu-dark); }
.quad-cell[data-quad="HN"] { background: var(--hn-light); color: var(--hn-dark); }
.quad-cell[data-quad="LU"] { background: var(--lu-light); color: var(--lu-dark); }
.quad-cell[data-quad="LN"] { background: var(--ln-light); color: var(--ln-dark); }
.quad-cell.is-selected { color: #fff; }
.quad-cell[data-quad="HU"].is-selected { background: var(--hu-dark); }
.quad-cell[data-quad="HN"].is-selected { background: var(--hn-dark); }
.quad-cell[data-quad="LU"].is-selected { background: var(--lu-dark); }
.quad-cell[data-quad="LN"].is-selected { background: var(--ln-dark); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.primary-btn {
  font-family: var(--font-body); font-size: 14px; font-weight: 600;
  color: var(--surface); background: var(--text);
  border: none; border-radius: 999px; padding: 9px 22px; cursor: pointer;
}
.primary-btn:hover { opacity: 0.9; }

/* ---------- Completed view ---------- */
.completed-view { padding-top: 4px; }
.completed-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.completed-head h2 { font-family: var(--font-head); font-weight: 700; font-size: 24px; margin: 0; }
.archive-week { margin-bottom: 24px; }
.archive-week-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.archive-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 12px; margin-bottom: 6px;
}
.archive-item .a-check { color: var(--ln-dark); font-size: 13px; }
.archive-item .a-title { font-size: 14px; color: var(--faint); text-decoration: line-through; flex: 1; }
.archive-item .a-tag { font-size: 11px; color: var(--faint); font-weight: 500; }
.empty-note { color: var(--faint); font-size: 14px; padding: 20px 4px; }

/* ---------- Passcode gate ---------- */
.pass-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 100;
}
.pass-card {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 12px;
  text-align: center;
}
.pass-title { font-family: var(--font-head); font-weight: 700; font-size: 26px; margin: 0; }
.pass-sub { color: var(--muted); font-size: 14px; margin: 0 0 4px; }
.pass-card .text-input { text-align: center; }
.pass-error { color: #c0392b; font-size: 13px; margin: 0; }
.pass-card .primary-btn { margin-top: 4px; }

/* ---------- Motion ---------- */
.detail-view { transform-origin: top left; }
@media (prefers-reduced-motion: reduce) {
  .pill-thumb, .seg, .filter, .quad-cell .q-tick, .quad-header, .detail-view, .back-btn,
  .card, .subs, .title, .title::after, .caret-btn .caret {
    transition: none !important;
  }
}

/* ---------- Responsive (iPhone) ---------- */
@media (max-width: 640px) {
  #app { padding: max(env(safe-area-inset-top), 16px) 14px 32px; }
  .board { grid-template-columns: 1fr; gap: 12px; }
  .board .quad-HU, .board .quad-HN { min-height: 220px; }
  .board .quad-LU, .board .quad-LN { min-height: 120px; }
  .form-grid { grid-template-columns: 1fr; gap: 20px; }
  .quad-picker { min-height: 170px; }
  .topbar { margin-bottom: 18px; }
  .seg { padding: 8px 12px; }
}
