:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --green: #1a7f37;
  --red: #cf222e;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #58a6ff;
    --green: #3fb950;
    --red: #f85149;
    --shadow: none;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.container {
  width: 100%; max-width: 560px;
  padding: 2rem 1rem calc(5rem + env(safe-area-inset-bottom));
}
h1 { font-size: 1.4rem; margin-bottom: 1.25rem; text-align: center; }

.login-wrap { padding-top: 3rem; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem; width: 100%;
  box-shadow: var(--shadow);
}
.login-card label { display: block; margin-bottom: 0.5rem; color: var(--muted); font-size: 0.85rem; }
.login-card input {
  width: 100%; padding: 0.6rem 0.75rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
  font-size: 1rem; margin-bottom: 1rem; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 0.6rem; background: var(--accent);
  color: #fff; border: none; border-radius: 6px;
  font-size: 0.95rem; cursor: pointer; font-weight: 600;
}
.login-card button:hover { opacity: 0.9; }
.login-error { color: var(--red); font-size: 0.85rem; margin-top: 0.5rem; text-align: center; }

.top-row { display: flex; justify-content: flex-end; margin-bottom: 0.5rem; }
.link-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 0.8rem; padding: 0.2rem 0.4rem;
}
.link-btn:hover { color: var(--red); }

.add-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.add-row input {
  flex: 1; padding: 0.6rem 0.75rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 1rem; outline: none;
}
.add-row input:focus { border-color: var(--accent); }
.add-row button {
  padding: 0.6rem 1rem; background: var(--accent); color: #fff;
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600;
  font-size: 0.95rem;
}

.section-header {
  list-style: none; color: var(--muted); font-size: 0.75rem;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.9rem 0.25rem 0.35rem;
}
.todo-list { list-style: none; }
.todo-item {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.6rem 0.7rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 0.35rem; cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, opacity 0.25s, transform 0.15s;
}
.todo-item.dragging {
  border-color: var(--accent);
  position: relative; z-index: 5;
  box-shadow: 0 8px 24px rgba(0,0,0,0.28);
  cursor: grabbing;
  transition: none; /* transform is driven by the pointer, not animated */
}
body.drag-noselect { user-select: none; -webkit-user-select: none; cursor: grabbing; }
body.drag-noselect .todo-item { cursor: grabbing; }
.todo-item.completing .todo-text { text-decoration: line-through; color: var(--muted); }
.todo-item.completing { opacity: 0.45; }
.todo-item.editing { cursor: default; display: block; }
.drag-handle {
  color: var(--muted); cursor: grab; font-size: 0.9rem;
  padding: 0.3rem 0.15rem; user-select: none; -webkit-user-select: none;
  flex-shrink: 0; touch-action: none;
}
.todo-num {
  color: var(--muted); font-size: 0.8rem; min-width: 1.5rem;
  text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums;
}
.todo-check {
  width: 20px; height: 20px; accent-color: var(--green);
  cursor: pointer; flex-shrink: 0;
}
.todo-main { flex: 1; min-width: 0; }
.todo-text { font-size: 0.95rem; overflow-wrap: break-word; }
.todo-note { font-size: 0.78rem; color: var(--muted); margin-top: 0.1rem; overflow-wrap: break-word; }
.todo-note a { color: var(--accent); }
.recur-badge { color: var(--accent); font-size: 0.8rem; margin-left: 0.3rem; }
.todo-item.done .todo-text { text-decoration: line-through; color: var(--muted); }
.todo-item.done .todo-num { color: var(--green); }
.icon-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 1rem; padding: 0.25rem 0.3rem; flex-shrink: 0;
  border-radius: 4px;
}
.icon-btn:hover { color: var(--text); background: var(--bg); }
.icon-btn.todo-del:hover { color: var(--red); }

/* Inline editor */
.edit-form { display: flex; flex-direction: column; gap: 0.5rem; }
.edit-form input[type="text"] {
  width: 100%; padding: 0.45rem 0.6rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.95rem; outline: none;
}
.edit-form input[type="text"]:focus { border-color: var(--accent); }
.edit-note-input { font-size: 0.82rem !important; }
.edit-opts { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); }
.edit-opts label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.edit-opts select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.15rem 0.3rem; font-size: 0.82rem;
}
.edit-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.edit-actions button {
  padding: 0.35rem 0.9rem; border-radius: 6px; font-size: 0.85rem;
  cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.edit-actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

.completed-divider {
  list-style: none; text-align: center; color: var(--muted); font-size: 0.8rem;
  padding: 0.5rem 0; margin-top: 0.25rem;
  border-top: 1px solid var(--border);
}
.clear-row { list-style: none; text-align: right; margin-top: 0.5rem; }
.clear-row button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.75rem; }
.clear-row button:hover { color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; font-size: 0.9rem; }

/* Toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 1rem; font-size: 0.85rem;
  display: flex; align-items: center; gap: 0.75rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 2rem); z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
#toast .toast-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#toast button {
  background: none; border: none; color: var(--accent);
  font-weight: 600; cursor: pointer; font-size: 0.85rem; flex-shrink: 0;
}

@media (max-width: 480px) {
  .todo-item { padding: 0.7rem 0.6rem; }
  .todo-check { width: 22px; height: 22px; }
}

/* Keyboard accessibility */
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.todo-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.foot-row { text-align: center; margin-top: 1.5rem; }

.due-badge { color: var(--muted); font-size: 0.75rem; margin-left: 0.4rem; white-space: nowrap; }
.edit-opts input[type="date"] {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.15rem 0.3rem; font-size: 0.82rem;
  color-scheme: light dark;
}

/* List tabs */
.list-tabs {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  justify-content: center; margin-bottom: 0.9rem;
}
.list-tab {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); border-radius: 999px; padding: 0.25rem 0.85rem;
  font-size: 0.82rem; cursor: pointer;
}
.list-tab:hover { color: var(--text); }
.list-tab.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.list-tab.list-add { padding: 0.25rem 0.6rem; }

/* ── List colours ──
   Light mode shows the colour as-is; dark mode blends it into the dark
   surface so text keeps its contrast. Done items get a faded mix. */
.tinted {
  --item-bg: var(--list-color);
  --item-bg-done: color-mix(in srgb, var(--list-color) 32%, var(--surface));
  --item-border: color-mix(in srgb, var(--list-color) 55%, var(--border));
  --item-border-done: color-mix(in srgb, var(--list-color) 22%, var(--border));
}
.list-tab.colored {
  --tab-bg: var(--tab-color);
  --tab-border: color-mix(in srgb, var(--tab-color) 60%, var(--border));
  background: var(--tab-bg);
  border-color: var(--tab-border);
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  /* 38% is about as far as the tint can go before light body text drops
     below a 4.5:1 ratio on the lightest pastels */
  .tinted {
    --item-bg: color-mix(in srgb, var(--list-color) 38%, var(--surface));
    --item-bg-done: color-mix(in srgb, var(--list-color) 15%, var(--surface));
    --item-border: color-mix(in srgb, var(--list-color) 46%, var(--border));
    --item-border-done: color-mix(in srgb, var(--list-color) 20%, var(--border));
  }
  .list-tab.colored {
    --tab-bg: color-mix(in srgb, var(--tab-color) 38%, var(--surface));
    --tab-border: color-mix(in srgb, var(--tab-color) 50%, var(--border));
  }
}
.tinted .todo-item { background: var(--item-bg); }
.tinted .todo-item:not(.dragging) { border-color: var(--item-border); }
.tinted .todo-item.done { background: var(--item-bg-done); border-color: var(--item-border-done); }
.list-tab.colored.active { border-color: color-mix(in srgb, var(--tab-color) 45%, var(--text)); }

/* List editor dialog */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  padding: 1.25rem; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 0.9rem;
}
.modal-card h2 { font-size: 1.05rem; }
.modal-card label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.modal-card input[type="text"] {
  width: 100%; padding: 0.5rem 0.65rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.95rem; outline: none;
}
.modal-card input[type="text"]:focus { border-color: var(--accent); }

.swatch-row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; padding: 0;
  border: 1px solid var(--border); cursor: pointer;
  background: var(--sw, var(--surface));
  flex-shrink: 0;
}
.swatch.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-none {
  background: linear-gradient(to top right,
    var(--surface) 44%, var(--red) 46%, var(--red) 54%, var(--surface) 56%);
}
@media (max-width: 480px) {
  .swatch { width: 38px; height: 38px; } /* comfortable touch target */
}
input[type="color"].swatch-custom { background: var(--surface); overflow: hidden; }
.swatch-custom::-webkit-color-swatch-wrapper { padding: 3px; }
.swatch-custom::-webkit-color-swatch { border: none; border-radius: 50%; }
.swatch-custom::-moz-color-swatch { border: none; border-radius: 50%; }
