* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 16px;
  color: #1f2937;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 760px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 32px 36px 20px;
  border-bottom: 1px solid #f1f5f9;
}

.header h1 {
  font-size: 34px;
  font-weight: 800;
  color: #111827;
  letter-spacing: -0.5px;
}

.subtitle {
  margin-top: 6px;
  color: #6b7280;
  font-size: 15px;
}

.todo-form {
  display: flex;
  gap: 10px;
  padding: 22px 36px;
}

#todo-input {
  flex: 1;
  padding: 16px 18px;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  font-size: 17px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}

#todo-input:focus {
  border-color: #7c5cff;
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.15);
}

.btn-add {
  background: #7c5cff;
  color: #fff;
  border: none;
  padding: 0 22px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-add:hover {
  background: #6a47ff;
}

.btn-add:active {
  transform: scale(0.97);
}

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 36px 14px;
  flex-wrap: wrap;
}

.filter {
  background: transparent;
  border: 1.5px solid #e5e7eb;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  color: #4b5563;
  cursor: pointer;
  transition: all 0.15s;
}

.filter:hover {
  border-color: #c4b5fd;
  color: #6a47ff;
}

.filter.active {
  background: #ede9fe;
  border-color: #c4b5fd;
  color: #6a47ff;
  font-weight: 700;
}

.clear-done {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #ef4444;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 4px;
}

.clear-done:hover {
  text-decoration: underline;
}

.todo-list {
  list-style: none;
  padding: 8px 16px 12px;
  flex: 1;
  min-height: 200px;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 14px;
  background: #f9fafb;
  border: 1.5px solid #f3f4f6;
  margin-bottom: 10px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.todo-item:hover {
  background: #f3f4f6;
  border-color: #e5e7eb;
}

.todo-item.dragging {
  background: #ede9fe;
  border-color: #c4b5fd;
  box-shadow: 0 12px 28px rgba(124, 92, 255, 0.25);
  opacity: 0.95;
  z-index: 10;
}

.todo-item.drop-target-above {
  border-top: 3px solid #7c5cff;
}

.todo-item.drop-target-below {
  border-bottom: 3px solid #7c5cff;
}

.drag-handle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 40px;
  cursor: grab;
  color: #9ca3af;
  font-size: 22px;
  line-height: 1;
  touch-action: none;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}

.drag-handle:hover {
  background: #e5e7eb;
  color: #6b7280;
}

.drag-handle:active {
  cursor: grabbing;
  background: #ddd6fe;
  color: #6a47ff;
}

.todo-item input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: #7c5cff;
  cursor: pointer;
  flex: 0 0 auto;
}

.todo-item .text {
  flex: 1;
  font-size: 17px;
  word-break: break-word;
  line-height: 1.4;
  min-width: 0;
}

.todo-item.done {
  background: #f9fafb;
  opacity: 0.7;
}

.todo-item.done .text {
  color: #9ca3af;
  text-decoration: line-through;
}

.todo-item .edit,
.todo-item .delete {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 20px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.15s;
}

.todo-item .delete {
  font-size: 24px;
}

.todo-item .edit:hover {
  color: #6a47ff;
  background: #ede9fe;
}

.todo-item .delete:hover {
  color: #ef4444;
  background: #fee2e2;
}

.edit-input {
  flex: 1;
  font-size: 17px;
  font-family: inherit;
  color: #111827;
  background: #ffffff;
  border: 1.5px solid #7c5cff;
  border-radius: 8px;
  padding: 8px 12px;
  outline: none;
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.15);
  min-width: 0;
}

.empty {
  text-align: center;
  color: #9ca3af;
  font-size: 15px;
  padding: 48px 16px;
  list-style: none;
}

.footer {
  padding: 18px 36px 24px;
  border-top: 1px solid #f1f5f9;
  color: #6b7280;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.hint {
  color: #9ca3af;
}

.grip {
  display: inline-block;
  padding: 0 4px;
  color: #7c5cff;
  font-weight: 700;
}

/* ---------- MÓVIL ---------- */
@media (max-width: 640px) {
  body {
    padding: 0;
    background-attachment: scroll;
  }

  .app {
    border-radius: 0;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 100%;
    box-shadow: none;
  }

  .header {
    padding: 24px 20px 16px;
    padding-top: max(24px, env(safe-area-inset-top));
  }

  .header h1 {
    font-size: 28px;
  }

  .subtitle {
    font-size: 14px;
  }

  .todo-form {
    padding: 16px 20px;
    gap: 8px;
  }

  #todo-input {
    padding: 14px 16px;
    font-size: 16px; /* evita zoom en iOS */
  }

  .btn-add {
    padding: 0 18px;
    font-size: 15px;
  }

  .filters {
    padding: 0 20px 12px;
    gap: 6px;
  }

  .filter {
    padding: 8px 14px;
    font-size: 13px;
  }

  .clear-done {
    width: 100%;
    margin-left: 0;
    text-align: left;
    padding: 8px 0 0;
  }

  .todo-list {
    padding: 6px 12px 8px;
  }

  .todo-item {
    padding: 14px 14px;
    gap: 10px;
    margin-bottom: 8px;
  }

  .drag-handle {
    width: 36px;
    height: 44px;
    font-size: 24px;
  }

  .todo-item input[type="checkbox"] {
    width: 24px;
    height: 24px;
  }

  .todo-item .text {
    font-size: 16px;
  }

  .todo-item .edit,
  .todo-item .delete {
    width: 44px;
    height: 44px;
  }

  .todo-item .edit {
    font-size: 22px;
  }

  .todo-item .delete {
    font-size: 26px;
  }

  .edit-input {
    font-size: 16px; /* evita zoom en iOS */
    padding: 10px 12px;
  }

  .footer {
    padding: 16px 20px 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    font-size: 12px;
  }

  .hint {
    font-size: 11px;
  }
}

@media (max-width: 380px) {
  .todo-form {
    flex-direction: column;
  }
  .btn-add {
    padding: 14px;
    width: 100%;
  }
}
