:root {
  /* Priority colors */
  --p0: #ef4444; /* Highest (red) */
  --p1: #f97316; /* High (orange) */
  --p2: #eab308; /* Medium (yellow) */
  --p3: #22c55e; /* Low (green) */

  --bg: #0b1220;
  --surface: #0f172a;
  --surface2: #111c33;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #24324d;
  --danger: #ef4444;
  --ok: #22c55e;

  /* Surfaces used by inputs/todos so themes can swap them. */
  --field: #0b162e;

  --radius: 14px;
  --tap: 44px;

  /* iOS safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Light mode swaps only the neutrals via CSS variables. */
html[data-theme='light'] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --field: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);

  /* iOS UX tweaks (requested): avoid blue tap highlight, text callout, selection */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* Allow text selection where it matters */
input, textarea, select {
  -webkit-user-select: text;
  user-select: text;
}
button { -webkit-tap-highlight-color: transparent; }

.skip-link {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  transform: translateY(-200%);
}
.skip-link:focus { transform: translateY(0); outline: 2px solid #93c5fd; }

.app {
  min-height: 100vh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  height: calc(44px + var(--safe-top));
  padding: var(--safe-top) 14px 0;
  background: var(--bg);
  border-bottom: 1px solid rgba(36,50,77,0.8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-sizing: border-box;
}

.topbar__title {
  font-weight: 650;
  letter-spacing: 0.2px;
  font-size: 18px;
}

.topbar__actions {
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.topbar__addBtn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
}

.main {
  padding: 14px;
  padding-top: calc(14px + 44px + var(--safe-top));
  padding-bottom: calc(14px + var(--safe-bottom) + 74px); /* keep content above tabbar */
}

.main:focus {
  outline: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stack { display: grid; gap: 10px; }

.btn {
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

.btn--primary { background: var(--surface2); border-color: var(--border); }
.btn--danger { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.35); }
.btn--ghost { background: transparent; }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.label { display: grid; gap: 6px; font-weight: 600; color: var(--muted); }

.list {
  display: grid;
  gap: 10px;
}

.todo {
  display: grid;
  gap: 0;
  padding: 4px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--field);
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* Project cards - same size/style as todo cards but lighter */
.projectCard {
  display: grid;
  gap: 0;
  padding: 4px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.6);
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.projectCard__row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.projectCard__info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.projectCard__name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.projectCard__count {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.projectCard__menuBtn {
  padding: 0;
  min-width: 24px;
  min-height: 24px;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-1px);
  background: none !important;
  border: none !important;
  color: var(--muted);
  vertical-align: middle;
}

/* Checklist view */
.checklist {
  display: grid;
  gap: 6px;
  touch-action: manipulation;
}

.checklist__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.checklist__item--done {
  opacity: 0.7;
}

.checklist__circle {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid var(--p2); /* active: yellow border */
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
}

.checklist__circle--done {
  border-color: var(--ok); /* completed: dark green border */
  background: transparent; /* hollow */
  color: var(--ok); /* check mark in same green */
}

.checklist__text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px;
}

.checklist__hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 6px 0;
  touch-action: manipulation;
}

/* Back button in topbar */
.topbar__backBtn {
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  font-weight: 400;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

@keyframes todoFadeOut {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-8px); }
}

@keyframes todoFadeIn {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes todoCollapse {
  0% { max-height: 160px; padding-top: 4px; padding-bottom: 4px; margin-top: 0; margin-bottom: 0; }
  100% { max-height: 0; padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; border-width: 0; }
}

.todo--fadeOut {
  animation: todoFadeOut 1200ms ease forwards, todoCollapse 1200ms ease forwards;
}

.todo--newCompleted {
  animation: todoFadeIn 1200ms ease;
}

.todo--flipMove {
  transition: transform 1500ms ease-in-out;
  will-change: transform;
}

.todo--animating {
  pointer-events: none;
}

.todo--slot {
  border-color: transparent;
  background: transparent;
  padding: 0;
}

.todo__title {
  font-weight: 600;
  line-height: 1.2;
  font-size: 15px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.todo__dueInline {
  white-space: nowrap;
  margin-right: 2px;
}

.todo__noteIcon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transform: translateY(-1px);
}

.todo__row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.todo__titleArea {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.todo__row2 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  min-height: 16px;
  padding-left: 28px;
}

.todo__checkWrap {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.todo__check {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2.5px solid var(--border);
  background: transparent;
  margin: 0;
  position: absolute;
  inset: 0;
}

.todo__checkIcon {
  display: none;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: var(--p3);
  position: relative;
  z-index: 1;
}

.todo__check:checked + .todo__checkIcon {
  display: block;
}

.todo__check:checked {
  background: rgba(34,197,94,0.18);
}

.todo[data-priority='P0'] .todo__check { border-color: var(--p0); }
.todo[data-priority='P1'] .todo__check { border-color: var(--p1); }
.todo[data-priority='P2'] .todo__check { border-color: var(--p2); }
.todo[data-priority='P3'] .todo__check { border-color: var(--p3); }

.todo[data-priority='P0'] .todo__checkIcon { color: var(--p0); }
.todo[data-priority='P1'] .todo__checkIcon { color: var(--p1); }
.todo[data-priority='P2'] .todo__checkIcon { color: var(--p2); }
.todo[data-priority='P3'] .todo__checkIcon { color: var(--p3); }

.todo__check:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.todo__check[disabled] {
  opacity: 0.55;
}

.todo__menuBtn {
  padding: 0;
  min-width: 24px;
  min-height: 24px;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-1px);
  background: none !important;
  border: none !important;
  color: var(--muted);
  vertical-align: middle;
}

.todo--dragging {
  position: fixed;
  z-index: 30;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  pointer-events: none;
  touch-action: none;
}

.todo--placeholder {
  border-style: dashed;
  opacity: 0.6;
}

.todo__title--done { text-decoration: line-through; opacity: 0.7; }

.todo__titleArea {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Completed section divider */
.todo-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
  padding: 0 4px;
}

.todo-divider::before,
.todo-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.todo-divider__text {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Days left tags */
.dueTag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(148,163,184,0.15);
  color: var(--muted);
}

@keyframes flashOpacity {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.1; }
}

.dueTag--overdue {
  background: rgba(239,68,68,0.15);
  color: var(--p0);
  animation: flashOpacity 2s ease-in-out infinite;
}

.dueTag--today {
  background: rgba(249,115,22,0.15);
  color: var(--p1);
  animation: flashOpacity 2s ease-in-out infinite;
}

.dueTag--soon {
  background: rgba(234,179,8,0.15);
  color: var(--p2);
  animation: flashOpacity 2s ease-in-out infinite;
}

/* Todo info page styles */
.todoInfo__title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.todoInfo__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.todoInfo__label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.todoInfo__value {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.todoInfo__section {
  padding: 10px 0;
}

.todoInfo__notes {
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(148,163,184,0.25);
}
.badge--p0 { color: var(--p0); }
.badge--p1 { color: var(--p1); }
.badge--p2 { color: var(--p2); }
.badge--p3 { color: var(--p3); }

.iconBtn {
  min-width: var(--tap);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(17,28,51,0.6);
  color: var(--text);
}
.iconBtn:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(36,50,77,0.9);
}

.tabbar__tab {
  min-height: var(--tap);
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}
.tabbar__tab[aria-current="page"] {
  color: var(--text);
  background: rgba(148,163,184,0.12);
}
.tabbar__tab:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

.modalHost {
  position: fixed;
  inset: 0;
  display: none;
  padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  background: rgba(0,0,0,0.5);
  z-index: 20;
}
.modalHost[aria-hidden="false"] { display: grid; align-items: end; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  max-height: min(82vh, 720px);
  overflow: auto;
}

.modal__header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.modal__title { font-weight: 750; font-size: 16px; }

.thumbGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.thumb {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--field);
}
.thumb img { width: 100%; height: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.thumb--clickable { cursor: pointer; }
.thumb--clickable:active { opacity: 0.8; }
.thumb button {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(239,68,68,0.35);
  background: rgba(239,68,68,0.15);
  color: var(--text);
  font-weight: 800;
}

.small { font-size: 12px; color: var(--muted); }
.hr { height: 1px; background: rgba(36,50,77,0.8); margin: 10px 0; }

/* Full-screen image viewer */
.imageViewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.imageViewer__close {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.imageViewer__counter {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  z-index: 10000;
}

.imageViewer__img {
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  object-fit: contain;
  transform-origin: center center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
