/* ------------------------------------------------------------------
   Theme tokens (light default, dark via prefers-color-scheme)
   ------------------------------------------------------------------ */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #1c1f26;
  --muted: #6b7280;
  --border: #e3e5ea;
  --accent: #2f7d5b;
  --accent-strong: #256649;
  --accent-soft: #e3f2ea;
  --danger: #c2413a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 2px 8px rgba(16, 24, 40, 0.05);
  --shadow-lift: 0 10px 28px rgba(16, 24, 40, 0.18);
  --radius: 12px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1c1f25;
    --surface-2: #23272e;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2e333b;
    --accent: #4fb589;
    --accent-strong: #67c79c;
    --accent-soft: #1f3a2e;
    --danger: #ef6b62;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 12px 30px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }

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

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------
   Layout
   ------------------------------------------------------------------ */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 16px 96px;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }

.summary { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* New-task form */
.new-task {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.new-task:focus-within { border-color: var(--accent); }

.new-task input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.new-task input:focus { outline: none; }

.btn-primary {
  padding: 10px 20px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms, transform 100ms;
}

.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: scale(0.97); }

.shake { animation: shake 360ms var(--ease); }

/* Toolbar: filters + clear */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: 18px 0 12px;
}

.filters {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 150ms, color 150ms;
}

.filter:hover { color: var(--text); }

.filter[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.badge {
  min-width: 1.5em;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--border);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.filter[aria-pressed="true"] .badge { background: var(--accent-soft); color: var(--accent-strong); }

.btn-link {
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.btn-link:hover:not(:disabled) { color: var(--danger); }
.btn-link:disabled { opacity: 0.45; cursor: default; }

/* ------------------------------------------------------------------
   Task list
   ------------------------------------------------------------------ */
.task-list {
  position: relative; /* offsetParent for drag calculations */
  margin: 0;
  padding: 0;
  list-style: none;
}

.task {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  margin-bottom: 8px;
  padding: 6px 6px 6px 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 180ms var(--ease), box-shadow 180ms, background-color 200ms,
    height 260ms var(--ease), opacity 220ms, margin 260ms var(--ease), padding 260ms var(--ease);
}

.task.entering { animation: task-in 280ms var(--ease); }

.task.leaving {
  height: 0 !important;
  min-height: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
  opacity: 0;
  transform: translateX(32px);
  pointer-events: none;
}

.task.dragging {
  z-index: 10;
  transition: box-shadow 180ms;
  box-shadow: var(--shadow-lift);
  cursor: grabbing;
}

/* Drag handle */
.handle {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: grab;
  touch-action: none; /* let pointer events handle touch drags */
  opacity: 0.55;
  transition: opacity 150ms;
}

.handle svg { width: 20px; height: 20px; fill: currentColor; }
.task:hover .handle, .handle:focus-visible, .dragging .handle { opacity: 1; }

/* Custom checkbox */
.check {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

.toggle {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.box {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 50%;
  transition: background-color 180ms, border-color 180ms;
}

.check:hover .box { border-color: var(--accent); }
.toggle:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 3px; }

.box svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: #fff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  transition: stroke-dashoffset 260ms var(--ease) 60ms;
}

.done .box { background: var(--accent); border-color: var(--accent); }
.done .box svg { stroke-dashoffset: 0; }
.just-done .box { animation: pop 320ms var(--ease); }

/* Task text; the strike-through fades in (works for wrapped lines too) */
.text {
  flex: 1;
  min-width: 0;
  padding: 8px 6px;
  overflow-wrap: anywhere;
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  text-decoration-color: transparent;
  transition: color 220ms, text-decoration-color 280ms;
  cursor: text;
}

.done .text {
  color: var(--muted);
  text-decoration-color: currentColor;
}

.editing .text, .editing .edit { display: none; }

.edit-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--surface-2);
  color: inherit;
  font: inherit;
}

.edit-input:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* Edit / delete icon buttons */
.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 150ms, color 150ms, background-color 150ms;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.task:hover .icon-btn, .icon-btn:focus-visible { opacity: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.delete:hover { color: var(--danger); }

/* Touch devices have no hover: always show the controls. */
@media (hover: none) {
  .icon-btn, .handle { opacity: 0.85; }
}

.empty {
  margin: 28px 0;
  color: var(--muted);
  text-align: center;
}

.hint, .notice {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.notice { color: var(--danger); }

@media (hover: none) { .hint { display: none; } }

/* ------------------------------------------------------------------
   Undo toast
   ------------------------------------------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 18px;
  border-radius: 999px;
  background: #24272e;
  color: #f2f3f5;
  box-shadow: var(--shadow-lift);
  transform: translate(-50%, 140%);
  opacity: 0;
  visibility: hidden;
  transition: transform 260ms var(--ease), opacity 200ms, visibility 0s 260ms;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
  visibility: visible;
  transition: transform 260ms var(--ease), opacity 200ms;
}

#toast-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

#toast-undo {
  flex: none;
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .toast { background: #e8eaee; color: #1c1f26; }
}

/* ------------------------------------------------------------------
   Small screens
   ------------------------------------------------------------------ */
@media (max-width: 480px) {
  .app { padding-top: 24px; }
  h1 { font-size: 1.6rem; }
  .toolbar { justify-content: center; }
  .filter { padding: 6px 10px; }
  .icon-btn { width: 36px; }
}

/* ------------------------------------------------------------------
   Keyframes
   ------------------------------------------------------------------ */
@keyframes task-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

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